Author Topic: problems with servercmd  (Read 2043 times)

before I say anything, im letting you know that im an utter nooblet at this stuff besides some experience i had with a different scripting language that is kind of similar.
basicly i've made this mod and enabled it in the addons list but when i try one of the functions it doesnt do anything.(later viewing of the console showed that it didnt reconize the command. If anyone could help, I would greatly appreciate it.
Im also interested in how i would go about making a system where you kill a tree for money(since my code deals with money).
Code: [Select]
function serverCmdgivemoney(%client,%reciever,%amount)
{
 if(%amount <= %client.money)
  %client.money -= %amount;
  %reciever.money += %amount;
  messageclient(%client,"","You gave up cash");
  messageclient(%reciever,"","you got this much money:" %amount");
}
function serverCmdshowmoney(%client)
{
 messageclient(%client,"","You have this much money" %client.money");
}
function serverCmdadmingivemoney(%client,%reciever,%amount)
{
 if(%client.isadmin)
  %reciever.money += %amount;
  messageclient(%reciever,"","you got this much money:" %amount");
}
Please help me. I need help. (so one day i might be a good modder too :cookieMonster:)

Well, for one thing, you cant just use  %receiver for the recieving client. You'd need to do a for to go through the ClientGroup and find who'se Client ID has that name.

Also, I noticed you didn't use any brackets...try this to check for errors (code-wise, not logic-wise) in the console: exec("add-ons/NameOfYourScript.cs"); and see if anything shows up in red if you haven't already.

As for interested in killing trees for money, you'd need to make a weapon that checks the collisions datablock to see if its "brickPineTreeData" if I remember right. When I get back my computer, I might post my RPG mod for people to use as a base for theirs. (Has tree chopping, DM money, etc.)

new code: oh and it didnt work i made some changes. plz tell me how far off i am from what you meant
Code: [Select]
function serverCmdgivemoney(%client,%reciever,%amount)
{
 %cn=ClientNameFinder(%reciever);
 if(%amount <= %client.money && cn)
 {
  %client.money -= %amount;
  %cn.money += %amount;
  messageclient(%client,"","You gave up cash");
  messageclient(%cn,"","you got this much money:" %amount");
 }
}
function serverCmdshowmoney(%client)
{
 messageclient(%client,"","You have this much money" %client.money");
}
function serverCmdadmingivemoney(%client,%reciever,%amount)
{
 %cn=ClientNameFinder(%reciever);
 if(%client.isadmin && %cn)
  {
  %cn.money += %amount;
  messageclient(%cn,"","you got this much money:" %amount");
  }
}
function ClientNameFinder(%name)
{
 if(%name $= "")
  return 0;
 for(%i=0;%i<ClientGroup.getCount();%i++){
  %cm = ClientGroup.getObject(%i);
  if(SubString(%cl.name, %name)){
   if(%victim){
    return 0;
   } else {
    %victim = %cl;
   }
  }
 }
 if(%victim){
  return %victim.player;
 } else {
  return 0;
 }
}

After taking the function from either Randy's PM mod (The original source) or my bots mod, you forgot to include the SubString function, needed for such a name finder to work.

Also, I'm unsure about this, but Terror suggested a way to make the SubString function less laggy: (One line rather than lots of code)
Code: [Select]
function SubString(%string,%substring)
{
 return (strStr(strLwr(%string),strLwr(%substring));
}

Everybody loves Terror.
I can't believe you used a loop for it before xD

Code: [Select]
messageclient(%cn,"","you got this much money:" %amount");An example of error'ed code, put a "," or "@" after the ":"" and take out the last """ like this:
Code: [Select]
messageclient(%cn,"","you got this much money: %1", %amount);
And
Code: [Select]
if(%amount <= %client.money && cn)
Code: [Select]
if(%amount <= %client.money && %cn)
I don't feel like correcting the whole thing, abut a lot of errors....

ok i made the changes and now it actually opens ^.^ buuuut... the only command that works is showmoney and it just says  You have this much money:
please help me with this. I really want to finish this add-on(cuz lots of people want something like this and all the good ones are never released.)
newest code
Code: [Select]
function serverCmdgivemoney(%client,%reciever,%amount)
{
 %cn=ClientNameFinder(%reciever);
 if(%amount <= %client.money && %cn)
 {
  %client.money -= %amount;
  %cn.money += %amount;
  messageclient(%client,"","You gave up cash");
  messageclient(%cn,"","you got this much money: ", %amount);
 }
}
function serverCmdshowmoney(%client)
{
 messageclient(%client,"","You have this much money: ", %client.money);
}
function serverCmdadmingivemoney(%client,%reciever,%amount)
{
 %cn=ClientNameFinder(%reciever);
 if(%client.isadmin && %cn)
  {
  %cn.money += %amount;
  messageclient(%cn,"","you got this much money: ", %amount);
  }
}
function ClientNameFinder(%name) //credit to space guy
{
 if(%name $= "")
  return 0;
 for(%i=0;%i<ClientGroup.getCount();%i++){
  %cm = ClientGroup.getObject(%i);
  if(SubString(%cl.name, %name)){
   if(%victim){
    return 0;
   } else {
    %victim = %cl;
   }
  }
 }
 if(%victim){
  return %victim.player;
 } else {
  return 0;
 }
}
function SubString(%string, %substring){
for(%i=0;%i<=strlen(%string) - strlen(%substring);%i++){
if(getSubStr(%string, %i, strlen(%substring)) $= %substring)
return 1;
}
return 0;
}

Off the top of my head, clientNameFinder seems to be confusing its variable names a lot. Example:
Code: [Select]
%cm = ClientGroup.getObject(%i);
  if(SubString(%cl.name, %name)){
   if(%victim){

You need to look at %cm.name, not %cl... Also, I'm pretty sure %victim will always return false, because I don't see it defined anywhere in the function.

Replace:
Code: [Select]
messageclient(%cn,"","you got this much money: ", %amount);With:
Code: [Select]
messageclient(%cn,"","you got this much money: %1", %amount);