Author Topic: Stuck on scripting  (Read 3393 times)

Code: [Select]
if(!%victim)
{
         %victim = findclientbyBL_ID(%target)
messageclient(%client, "", "No player was found.");
return;
}
They're the same condition, so you can do that.

Also, make sure you keep your variables all the same. You're randomly switching from %name to %target. Change the %name argument in the function to %target. Or change all your %target's to %name.

Ok, whatabout this
Code: [Select]
function servercmdBuyBow(%client)
{
if(%client.score >= "1")
{
findclientbyname(%client).player.addItem(BowItem);
}
else messageclient(%client, "", "\c3You need 5 points");
}






function Player::addItem(%this,%item)
{
   for(%i = 0; %i < %this.getDatablock().maxTools; %i++)
   {
      %tool = %this.tool[%i];
      if(%tool == 0)
      {
         %this.tool[%i] = %item;
         %this.weaponCount++;
         messageClient(%this.client,'MsgItemPickup','',%i,%item);
         break;
      }
   }
}

findclientbyname(heed).player.addItem(wrenchItem);
For the server cmd, it doesn't add the bow. It knows that the points exist but it doesn't add the item.

%client is an integer, not the players name. So for example in your findClientByName() is technically searching this: findClientByName(125583).player.addItem(bla);. You already have %client in the arguments, so you can replace findClientByName() with just %client. Also your checking if the clients score as a string, you need to remove the quotes around "1" so it becomes an integer, although I'm not sure if that affects it. Last thing I see is that you're checking if the clients score is greater than 1, and if its not, your messaging them saying they need 5 points.

To subtract score would I do

%client.score - 5;

%client.score -= 5;
OR
%client.score = %client.score - 5;
« Last Edit: November 05, 2009, 09:23:16 PM by lilboarder32 »

To subtract score would I do

%client.score - 5;

%client.score - 5; would just be like saying to someone "What is your age minus five"? It wouldn't actually make your age that value.


%client.score = %client.score - 5; would work because it would be like saying:

"Your age is now what your age is minus 5"


= stands for assignment, so it assigns what the expression on the right evaluates to to the left variable.

Edit: I just realized my example of "Your age is now" works well, because you couldn't do:

"Your age is now minus 5", that doesn't make sense and it would make you -5 years old. (%client.score = -5;)


You can do %client.score -= 5; because that is a built in feature in a lot of programming languages that basically shortens your statements.


%client.score += 5; or -= 5; or *= 5 or /= 5.

(idk if torquescript does modulus)
« Last Edit: November 06, 2009, 12:01:46 AM by Zenthos »

%client.score - 5; would just be like saying to someone "What is your age minus five"? It wouldn't actually make your age that value.


%client.score = %client.score - 5; would work because it would be like saying:

"Your age is now what your age is minus 5"


= stands for assignment, so it assigns what the expression on the right evaluates to to the left variable.

Edit: I just realized my example of "Your age is now" works well, because you couldn't do:

"Your age is now minus 5", that doesn't make sense and it would make you -5 years old. (%client.score = -5;)


You can do %client.score -= 5; because that is a built in feature in a lot of programming languages that basically shortens your statements.


%client.score += 5; or -= 5; or *= 5 or /= 5.

(idk if torquescript does modulus)
A little late there...
%client.score -= 5;
OR
%client.score = %client.score - 5;

A little late there...

He's explaining it, rather than just throwing code around.