AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Args and stuff (https://forums.alliedmods.net/showthread.php?t=25885)

NewUser 03-22-2006 19:15

Args and stuff
 
Let's say I created something new.

Code:

new cash[33];
Let's say someone made a deal with someone else. They transfer some cash over to the other user. How would I do that? amx_cashgive playername value; Detecting: If they have enough cash that they're putting for the value. Seeing if the user exists. Seeing if they're being specific enough about the username incase there are two people with similar names. Taking away the cash from the giver. Giving the receiver the value the giver typed in.

v3x 03-22-2006 19:22

Code:
register_clcmd("amx_cmd" , "my_cmd");
Code:
public my_cmd(id) {   new arg1[33] , arg2[33];   read_argv(1 , arg1 , 32);   read_argv(2 , arg2 , 32);   new player = cmd_target(id , arg1 , 0);   if(!player) return PLUGIN_HANDLED;   new money = str_to_num(arg2);   if(money) {     cash[player] += money;   }   return PLUGIN_HANDLED; }

Hawk552 03-22-2006 19:27

Quote:

Originally Posted by v3x
Code:
register_clcmd("amx_cmd" , "my_cmd");
Code:
public my_cmd(id) {   new arg1[33] , arg2[33];   read_argv(1 , arg1 , 32);   read_argv(2 , arg2 , 32);   new player = cmd_target(id , arg1 , 0);   if(!player) return PLUGIN_HANDLED;   new money = str_to_num(arg2);   if(money) {     cash[player] += money;   }   return PLUGIN_HANDLED; }

Wow v3x, you completely forgot to decrease the money from the other person.

Code:
cash[id] -= money;

EDIT: You also forgot to check if the person has enough money to give.

Code:
money = clamp(money,1,cs_get_user_money(id))

v3x 03-22-2006 19:32

zomg basic example - not going to spoon feed him.

NewUser 03-26-2006 16:00

Not to be a pest. But would this code function properly?

Code:
public gaben(id) {     new arg1[33], arg2[33];     read_argv(1, arg1, 32);     read_argv(2, arg2, 32);         new player = cmd_target(id, arg1, 0);         if(!player) return PLUGIN_HANDLED;         new cash2 = str_to_num(arg2);         if(cash2) {         Cash[player] += cash2;         Cash[id] -= cash2;         cash2 = clamp(cash2,1,Cash[id])     }     return PLUGIN_HANDLED; }

I just want to make sure. Since it's not specifically for CS.

Hawk552 03-26-2006 16:19

Quote:

Originally Posted by NewUser
Not to be a pest. But would this code function properly?

Code:
public gaben(id) {     new arg1[33], arg2[33];     read_argv(1, arg1, 32);     read_argv(2, arg2, 32);         new player = cmd_target(id, arg1, 0);         if(!player) return PLUGIN_HANDLED;         new cash2 = str_to_num(arg2);         if(cash2) {         cash2 = clamp(cash2,0,Cash[id]);             Cash[player] += cash2;         Cash[id] -= cash2;     }     return PLUGIN_HANDLED; }

I just want to make sure. Since it's not specifically for CS.



All times are GMT -4. The time now is 16:32.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.