Help with beginner torque problem :s (Need more help)

Author Topic: Help with beginner torque problem :s (Need more help)  (Read 1469 times)

So, i am making anything for the first time ever. So far i've only tried to slightly modify code etc. I try to do a Server command /up (velocity), but it's not doing what i want it to (duh), can someone glance over the code, facepalm and tell me what is wrong?

function serverCmdup(%client,%up)
{
   findclientbyname(%client).player.setVelocity("0 0 %up");
}
« Last Edit: August 22, 2014, 05:55:43 AM by Dannu »

You put the variable inside the quotation marks. It needs to be outside in order to work. Put it out and put SPC between it to connect the two. SPC will connect them with a space and @ will do it without a space.

Also %client is already assigned as you when you type the command so doing findClientByName won't work. Just do %client.

Thanks. I also figured out something else that has been confusing me lately. ^^

Just to not cludder the topic section, i will ask another question here.
I've taken on a new project(?). Sort of a economy thing? My questions are.. How do i make a wallet money system (stats), how do i make a HUD that displays on spawn and how do i chatmessageall, centerprintall, bottomprintall etc.

If you're confused at what i'm requesting, then the current code should fill in a few blanks:

Quote
//ATTEMPT AT A BEGINNER handicapped CURRENCY SYSTEM
function serverCmdeconomymoney(%client)
{
   %client.chatmessage("<color:ffffff><font:impact:20>Currently, the economy has "@$economymoney@ " <color:ffffff><font:impact:20>dollars on their bank account");
}
function servercmdrestarteconomy(%client)
{
   $economymoney = "0";
   %client.chatmessage("<color:ffffff><font:impact:20> The Economy has collapsed!");
}
function serverCmdMakeMoney(%client)
{
   $economymoney = $economymoney + 5;
   
   %client.chatmessage("<color:ffffff><font:impact:20>You have earned 5 dollars for the totalitarian government");
}

You could parent/package the code that's called when someone first spawns (take a look at the spawn message add-on if you're unsure) and then make a schedule for every 30 seconds or so to update the bottom print.

schedule(time, id, "function");
commandToClient(%client,'bottomPrint', "cash money:" SPC %client.money);

Obviously you'd have to have some kind of saving/database thing if you're gonna have stats but if it's only money you could use incScore and just use the players score.
If you put the schedule in the function to send the bottom print then every time it's called it will resend the bottomPrint and call the function again

I suggest putting the schedule in a global variable and using cancel() to stop it at the start of the function.
For example

function ball()
{
    cancel($ballSchedule);
    echo("ball");
    $ballSchedule = schedule(1000, 0, "ball");
}

If you're confused at what i'm requesting, then the current code should fill in a few blanks:

Quote
//ATTEMPT AT A BEGINNER handicapped CURRENCY SYSTEM
function serverCmdeconomymoney(%client)
{
   %client.chatmessage("<color:ffffff><font:impact:20>Currently, the economy has "@$economymoney@ " <color:ffffff><font:impact:20>dollars on their bank account");
}
function servercmdrestarteconomy(%client)
{
   $economymoney = "0";
   %client.chatmessage("<color:ffffff><font:impact:20> The Economy has collapsed!");
}
function serverCmdMakeMoney(%client)
{
   $economymoney = $economymoney + 5;
   
   %client.chatmessage("<color:ffffff><font:impact:20>You have earned 5 dollars for the totalitarian government");
}
1. You can use \cNUMBER to change the color instead. Say /colorTest in a server you're admin on to see all the colors. \c6 is white. You also won't need to do it again after the variable is inserted into the message.
2. Instead of doing "message " @ $var @ " stuff" do "message" SPC $var SPC "stuff". It annoys me.
3. If you're assigning a var to a number, the value does not have to be in quotations. Although it can be if you prefer it that way.
4. Instead of doing $var = $var + 5; you can do $var += 5; again, just a preference.

Also, please put your code in [code][/code] blocks next time.

Just to not cludder the topic section, i will ask another question here.
I've taken on a new project(?). Sort of a economy thing? My questions are.. How do i make a wallet money system (stats), how do i make a HUD that displays on spawn and how do i chatmessageall, centerprintall, bottomprintall etc.

Crown posted before me. So I'll give up on this post.


I'll try to figure it out and get back to you

Obviously you'd have to have some kind of saving/database thing if you're gonna have stats but if it's only money you could use incScore and just use the players score.
How would i go about checking it and, although i have some ideas, how exactly would i go about changing it

To save/check a database add-ons normally just use a .txt file, so you could write something like %client.bl_id TAB %client.money TAB %more_Vars on one line of a text file for everybody, then check the first line to see if it matches someone's ID. Iirc the functions for writing/reading files is normally written like
Code: [Select]
function blah(%path,%line)
{
   %file = new FileObject();
   if(!isWriteableFileName(%path))
      return;
   %file.openForWrite(%path);
   %file.writeLine(%line);
   %file.close();
   %file.delete();
}


function blah2(%path)
{
   %file=new fileobject();
   if(!isFile(%path))
      return;
   %file.openForRead(%path);
   %file.readLine();
   %file.close();
   %file.delete();
}

And usually on the reading you'll find something like while(!%file.isEOF()) to create a loop that will go through each and every line in said file.

That appears to be way too advanced for my skills and the purpose of it. How would i increment, decrement, check and display SCORE, to use that to check money
« Last Edit: August 22, 2014, 09:09:21 AM by Dannu »

That appears to be way too advanced for my skills and the purpose of it. How would i increment, decrement, check and display code?
Well if you're doing the score variable it'll be %client.score+=%number to increment, and %client.score-=%number to decrement, so you could have an admin only command to add or subtract ones score like
Code: [Select]
function serverCmdPlayerScore(%client,%name,%amount)
{
   if(!%client.isSuperAdmin)
   {
      messageClient(%client,'',"\c6You must be a \c3SuperAdmin\c6 to use this command.");
      return;
   }
   %target=findclientbyname(%name);
   if(!isObject(%target))
   {
      messageClient(%client,'',"\c3" @ %name SPC "\c6 is not a valid target.");
      return;
   }
   if(%amount<=-1 && %amount >= -9999)
   {
      %amount=mFloor(%amount);
      %target.score-=%amount;
      messageClient(%client,'',"\c6You lowered\c3" SPC %target.name @ "\c6's score by\c3" SPC %amount);
   }
   else if(%amount>=1 && %amount <= 9999)
   {
      %amount=mFloor(%amount);
      %target.score+=%amount;
      messageClient(%client,'',"\c6You raised\c3" SPC %target.name @ "\c6's score by\c3" SPC %amount);
   }
   else
   {
      messageClient(%client,'',"\c3" @ %amount SPC "is not a valid value.");
   }
}
There may be syntax errors, sorry if there are any.
This will take /PlayerScore name amount obviously to alter ones score, there is a command already for this though, but if you wanted to do your own variable, like %client.money instead of score, you can do it with this. Using mFloor it will make sure that no decimals are used, and obviously trying to change it by 0, or something that is not a number wont work. \c6 is colour code for white, and \c3 iirc is for yellow.

To check that %amount is in fact a valid number this uses two different values and uses && to make sure %amount is in fact between them. && means and, and || means or.

The two if statements with returns after them are made to check if you can actually target the player you wish, or if the client is a super admin. The ! means not, so if(!%client.isSuperAdmin) means if the client is not a Super Admin. The return; will stop the function right then and there, so if the client isn't super admin it'll message them then stop instead of trying to continue on. Same with check if %client exists or not.

display SCORE, to use that to check money
Lol wrote a wall of text before you edited it.
For score you can use %client.incScore(%number); instead of all that BS up there, so something simple like
Code: [Select]
function servercmdPlayerScore(%client,%name,%amount)
{
   if(!%client.isSuperAdmin)
   {
      messageClient(%client,'',"\c6You must be a \c3SuperAdmin\c6 to use this command.");
      return;
   }
   %target=findclientbyname(%name);
   if(!isObject(%target))
   {
      messageClient(%client,'',"\c3" @ %name SPC "\c6 is not a valid target.");
      return;
   }
   %target.incScore(%amount);
}
Will work just fine.
To display it you can use commandToClient(%client,'bottomPrint', "\c6Score:\c4" SPC %client.score);
« Last Edit: August 22, 2014, 09:27:21 AM by Thorfin25 »

Thanks a lot, very understandable and detailed, also cleared up a lot of features, i wasn't quite yet sure how to use.