Author Topic: /addmoney #updated#  (Read 1190 times)

if i wanted to add a script to add money/exp to a client. using Mctwists RP mod how would i do it

is this all i need?

for money
Code: [Select]
//command
function servercmdaddmoney(%client, %money)
{
%target = findclientbyname(%client);
%target.addmoney(%money);
}

for exp
Code: [Select]
//command
function servercmdaddexp(%client, %exp)
{
%target = findclientbyname(%client);
%target.addexp(%exp);
}

do i need to add to it?

#update#

i cant get it to work.
Code: [Select]
if(!isPackage(RP_Core))
   return;
   
if(!isPackage(RP_Money))
   return;

if(isPackage(RP_AddMoney))
deactivatePackage(RP_AddMoney);

package RP_AddMoney {

function servercmdaddMoney(%client,%money,%targetname)
{
   if(%client.isSuperAdmin)
   {
      %target = %client;
      if(%targetname !$= "")
         %target = findClientByName(%targetname);

      if(isObject(%target))
         %target.RPDB.addvalue("money",%money);
   }

};

activatePackage(RP_AddMoney);





whats wrong with it?
« Last Edit: October 26, 2009, 01:37:00 PM by dudeman68 »

First of all %client is a number not a name.
Second of all there are several ways to make this script more compact.
You can simply do

Code: [Select]
//command
function servercmdaddmoney(%client, %money)
{
%target = %client;
%target.addmoney(%money);
}

Code: [Select]
//command
function servercmdaddexp(%client, %exp)
{
%target = %client;
%target.addexp(%exp);
}


Also, have you already defined the addexp and addmoney function?

Code: [Select]
//command
function servercmdaddmoney(%client, %money)
{
%target = %client;
%target.addmoney(%money);
}

Why are you reassigning %client...?

Code: [Select]
function serverCmdAddMoney(%client,%money)
{
     %client.addMoney(%money);
}

Thanks for the help so far but I still need to know two things.
1. How would I make it a function?
2. I need to make it superadmin only.

%client (the first argument) is the client who is using it; so there is no targeting (which is a horrid idea). Try:
Code: [Select]
function servercmdAddMoney(%client,%money,%targetname)
{
   if(%client.isSuperAdmin)
   {
      %target = %client;
      if(%targetname !$= "")
         %target = findClientByName(%targetname);

      if(isObject(%target))
         %target.addMoney(%money);
   }
}
Assuming that addMoney is the correct method, of course. So this would be
Code: [Select]
/addmoney 350 dudeTo add $350 to 'dude'. Or:
Code: [Select]
/addmoney 350To add $350 to yourself.

Of course it's a good idea to give it some output; such as telling you you've added X amount to Y person and telling them they've had it added to them, and if you feel like being fancy even make it only use one message if the target is yourself.

Good luck.

Thank you M Truce and deep2

Update

sorry for double post
« Last Edit: October 26, 2009, 01:40:27 PM by dudeman68 »

You don't have addMoney as a valid method. You could try something like:
Code: [Select]
function GameConnection::addMoney(%this,%money)
{
   if(isObject(%this))
   {
      %this.money += %money;
   }
}
FakeEdit: Unless their is an addMoney method in the RP thing your editing, then disregard this. I haven't looked into that mod.

Especially when you're starting scripting, indent everything, like so:

Code: [Select]
if(!isPackage(RP_Core))
return;
   
if(!isPackage(RP_Money))
return;

if(isPackage(RP_AddMoney))
deactivatePackage(RP_AddMoney);

package RP_AddMoney
{
function servercmdaddMoney(%client,%money,%targetname)
{
if(%client.isSuperAdmin)
{
%target = %client;

if(%targetname !$= "")
%target = findClientByName(%targetname);

if(isObject(%target))
%target.RPDB.addvalue("money",%money);
}
};
activatePackage(RP_AddMoney);

Now do you see why it's syntax erroring?
Also, you don't need a package unless the function already exists.

so i dont need the packages? what do you mean by %this?

You don't have addMoney as a valid method. You could try something like:
Code: [Select]
function GameConnection::addMoney(%this,%money)
{
   if(isObject(%this))
   {
      %this.money += %money;
   }
}
FakeEdit: Unless their is an addMoney method in the RP thing your editing, then disregard this. I haven't looked into that mod.

also there is a script witch adds money i just dont know how to use it

Code: [Select]
RPDB.addvalue("money", 0);
« Last Edit: October 27, 2009, 10:24:17 PM by dudeman68 »

also there is a script witch adds money i just dont know how to use it

Code: [Select]
RPDB.addvalue("money", 0);

dumpconsolefunctions();

i got it to work by finding the right value names.

thanks to everyone who helped

*locked*