AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Store custom command and value for each client which is callable and changeable (https://forums.alliedmods.net/showthread.php?t=41339)

Silencer123 07-13-2006 07:19

Store custom command and value for each client which is callable and changeable
 
How do I create a custom command with value for each client which is callable and changeable
and stored for the time the player is on the server?
I need something like that to make player pay any kind of virtual money for the ammo in menu.
(See code)

Code:

#include <amxmodx>
#include <fun>
public plugin_init()
{
  register_plugin("SC Give Ammo","1.0","Silencer")
  register_menucmd(register_menuid("Ammo Menu"),1023,"SCitemMenuChoice")
  register_concmd("sc_giveammo", "check", 1, "- Enter sc_giveammo and select an option")
  register_concmd("sc_toggle_giveammo","toggle",ADMIN_MENU,"<1|0> - Turns SC Ammo Menu On or Off.")
  register_cvar("scgiveammo_toggle","1",FCVAR_SERVER)
  set_cvar_string("scgiveammo_toggle","1")
}
public toggle(id)
{
 if(get_cvar_num("scgiveammo_toggle")==1)
 {
  set_cvar_string("scgiveammo_toggle","0")
  client_print(0,print_chat,"[AMXX] SC Ammo has been disabled by the admin!")
  server_print("SC Ammo menu has been disabled!")
 }
 else
 {
  set_cvar_string("scgiveammo_toggle","1")
  client_print(0,print_chat,"[AMXX] SC Ammo has been enabled by the admin!")
  server_print("SC Ammo menu has been enabled!")
 }
 return PLUGIN_HANDLED
}
public check(id)
{
 if(get_cvar_num("scgiveammo_toggle")==0)
 {
  client_print(id,print_chat,"[AMXX] SC Ammo menu is currently disabled!")
 }
 else
 {
    SCitemMenu(id)
 }
 return PLUGIN_HANDLED
}
public SCitemMenu(id)
{
 if (is_user_alive(id))
 {
  new menuBody[1024]
  new key
  format(menuBody, 1023, "Ammo Menu^n^n 1.  357 Ammo^n 2.  Shotgun Ammo^n 3.  Sniperrifle Ammo^n 4.  Crossbow Ammo^n 5.  Energy Cells^n 6.  RPG Rockets^n 7.  AR Grenades^n 8.  9mm Ammo^n 9.  Minigun Rounds^n^n 0.  Cancel")
  key = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9)
  show_menu(id, key, menuBody)
 }
}
public SCitemMenuChoice(id, key)
{
 new Client[21]
 get_user_name(id,Client,20)
 switch(key)
 {
  case 0:
  {
  set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)
  show_hudmessage(0, "[AMXX] %s has got six Rounds for the 357",Client)
  give_item(id,"ammo_357")
 
  }
  case 1:
  {
  set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)
  show_hudmessage(0, "[AMXX] %s has got twelve Buckshots for the Shotgun",Client)
  give_item(id,"ammo_buckshot")
  }
  case 2:
  {
  set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)
  show_hudmessage(0, "[AMXX] %s has got five Bullets for the Sniperrifle",Client)
  give_item(id,"ammo_762")
  }
  case 3:
  {
  set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)
  show_hudmessage(0, "[AMXX] %s has got five Arrows for the Crossbow",Client)
  give_item(id,"ammo_crossbow")
  }
  case 4:
  {
  set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)
  show_hudmessage(0, "[AMXX] %s has got 20 Energy Cells for the Gauss and Egon",Client)
  give_item(id,"ammo_gaussclip")
  }
  case 5:
  {
  set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)
  show_hudmessage(0, "[AMXX] %s has got two Rockets for the RPG Launcher",Client)
  give_item(id,"ammo_rpgclip")
  }
  case 6:
  {
  set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)
  show_hudmessage(0, "[AMXX] %s has got two AR Grenades for the 9mm AR",Client)
  give_item(id,"ammo_ARgrenades")
  }
  case 7:
  {
  set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)
  show_hudmessage(0, "[AMXX] %s has got 17 9mm Bullets",Client)
  give_item(id,"ammo_9mmclip")
  }
  case 8:
  {
  set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)
  show_hudmessage(0, "[AMXX] %s has got 100 Rounds for the Minigun",Client)
  give_item(id,"ammo_556")
  }
  case 9:
  {
  }
 }
 return PLUGIN_HANDLED
}


Silencer123 07-14-2006 11:40

Re: Store custom command and value for each client which is callable and changeable
 
Okay... I tried a lot but there was no success, yet,
just compiling errors, which includes "Too many errors in a line"!
:O
Please help!

Shurik3n 07-14-2006 13:56

Re: Store custom command and value for each client which is callable and changeable
 
Your probably going to want to use a global variable for the clients money. Like
Code:
#include <amxmodx> #include <fun> new g_money[33] plugin_init()..

Then whenever somebody buys something you would do:
Code:
public SCitemMenuChoice(id, key)     {     new Client[21]     get_user_name(id,Client,20)     switch(key)     {         case 0:         {             set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)             show_hudmessage(0, "[AMXX] %s has got six Rounds for the 357",Client)             give_item(id,"ammo_357")             g_money[id] - price                     }

Of course you will still need a way for giving players money.

Silencer123 07-14-2006 15:00

Re: Store custom command and value for each client which is callable and changeable
 
/home/groups/amxmodx/tmp3/textX8a1xw.sma(79 -- 80) : warning 215: expression has no effect
/home/groups/amxmodx/tmp3/textX8a1xw.sma(140) : warning 217: loose indentation

2 warnings :/
I now have this:



Code:

/* AMX Mod X script.
* SC Give Ammo - Version 1.0 by Silencer
*/
#include <amxmodx>
#include <amxmisc>
#include <fun>
new g_money[33]
public plugin_init()
{
 register_plugin("SC Buy Ammo","1.0","Silencer")
 register_menucmd(register_menuid("Ammo Menu"),1023,"SCitemMenuChoice")
 register_concmd("amx_sc_buyammo", "check", 1, "- Enter amx_sc_buyammo and select an option")
 register_concmd("amx_sc_buyammo_status","toggle",ADMIN_LEVEL_A,"<1|0> - Turns SC Ammo Menu On or Off.")
 register_concmd("amx_sc_buyammo_money","g_money",ADMIN_LEVEL_A,"<Playername> <Value bigger than -1> - Set Players Money.")
 register_cvar("amx_sc_buyammo_toggle","1",FCVAR_SERVER)
 set_cvar_string("amx_sc_buyammo_toggle","1")
}
public toggle(id)
{
 if(get_cvar_num("amx_sc_buyammo_toggle")==1)
 {
  set_cvar_string("amx_sc_buyammo_toggle","0")
  client_print(0,print_chat,"[AMXX] SC Buy Ammo has been disabled by the admin!")
  server_print("SC Ammo menu has been disabled!")
 }
 else
 {
  set_cvar_string("amx_sc_buyammo_toggle","1")
  client_print(0,print_chat,"[AMXX] SC Buy Ammo has been enabled by the admin!")
  server_print("SC Ammo menu has been enabled!")
 }
 return PLUGIN_HANDLED
}
public check(id)
{
 if(get_cvar_num("amx_sc_buyammo_toggle")==0)
 {
  client_print(id,print_chat,"[AMXX] SC Buy Ammo menu is currently disabled!")
 }
 else
 {
  SCitemMenu(id)
 }
 return PLUGIN_HANDLED
}
public SCitemMenu(id)
{
 if (is_user_alive(id))
 {
  new menuBody[1024]
  new key
 
  format(menuBody, 1023, "Buy Ammo Menu^n^n 1.  Buy 357 Ammo^n 2.  Shotgun Ammo^n 3.  Sniperrifle Ammo^n 4.  Crossbow Ammo^n 5.  Energy Cells^n 6.  RPG Rockets^n 7.  AR Grenades^n 8.  9mm Ammo^n 9.  Minigun Rounds^n^n 0.  Cancel")
  key = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9)
 
  show_menu(id, key, menuBody)
 }
}
public SCitemMenuChoice(id, key)
{
 new Client[21]
 get_user_name(id,Client,20)
 
 switch(key)
{
 case 0:
{
 if(get_cvar_num("g_money")>99)
 {
  give_item(id,"ammo_357")
  client_print(id,print_chat,"[AMXX] You bought six Rounds for the 357!")
  g_money[id] - 100
 }
 else
 {
  client_print(id,print_chat,"[AMXX] You do not have enough money!")
 }
 return PLUGIN_HANDLED
}
case 1:
{
set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)
show_hudmessage(0, "[AMXX] %s has got twelve Buckshots for the Shotgun",Client)
give_item(id,"ammo_buckshot")
}
case 2:
{
set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)
show_hudmessage(0, "[AMXX] %s has got five Bullets for the Sniperrifle",Client)
give_item(id,"ammo_762")
}
case 3:
{
set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)
show_hudmessage(0, "[AMXX] %s has got five Arrows for the Crossbow",Client)
give_item(id,"ammo_crossbow")
}
case 4:
{
set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)
show_hudmessage(0, "[AMXX] %s has got 20 Energy Cells for the Gauss and Egon",Client)
give_item(id,"ammo_gaussclip")
}
case 5:
{
set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)
show_hudmessage(0, "[AMXX] %s has got two Rockets for the RPG Launcher",Client)
give_item(id,"ammo_rpgclip")
}
case 6:
{
set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)
show_hudmessage(0, "[AMXX] %s has got two AR Grenades for the 9mm AR",Client)
give_item(id,"ammo_ARgrenades")
}
case 7:
{
set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)
show_hudmessage(0, "[AMXX] %s has got 17 9mm Bullets",Client)
give_item(id,"ammo_9mmclip")
}
case 8:
{
set_hudmessage(100,110,125, 0.02, 0.73, 0, 6.0, 2.0, 0.1, 0.2, 4)
show_hudmessage(0, "[AMXX] %s has got 100 Rounds for the Minigun",Client)
give_item(id,"ammo_556")
}
case 9:
{
}
}
return PLUGIN_HANDLED
}


Shurik3n 07-14-2006 15:47

Re: Store custom command and value for each client which is callable and changeable
 
Use
Code:
 g_money[id] -= 100
and indent your code.

Silencer123 07-14-2006 16:44

Re: Store custom command and value for each client which is callable and changeable
 
ah yes you are right. thanks so far! I still need to know one more thing:
how do i register a command to set money for each player?
I have:
Code:


 register_concmd("amx_sc_buyammo_money","set_money",ADMIN_LEVEL_A,"<Playername> <Value bigger than -1> - Set Players Money.")

but now I need to know what to change here, so amxmodx
knows that the command needs a target/name and a value to work properly.
Code:

public set_money(id, value)
{
 return PLUGIN_HANDLED
}

EDIT: how to trigger internal defined function each time a player joins?
I need this to set the money value to 0 for each player connecting
Or can I even save money by steamid in a cfg or so without php and mysql stuff? O_o
Can i write that into plugin_init? Sorry, but I just started ^^"

EDIT2: I used indenter and it did not place Tabstops correctly after some lines.
(I manually corrected - indentation warning finally fixed)

Shurik3n 07-14-2006 17:16

Re: Store custom command and value for each client which is callable and changeable
 
Ok put the register_concmd in plugin_init then for the actual function do something like this:
Code:
public set_money(id,level,cid) {     if (!cmd_access(id, level, cid, ADMIN_LEVEL_A))         return PLUGIN_HANDLED     //Declare new array variables to hold the arguments     new arg[32],arg2[32]     //Read what the player typed into the console as the arguments     read_argv(1,arg,31)     read_argv(2,arg2,31)     //Create a new variable for the target and have it be giving the ID of the player in the first argument     new target = cmd_target(id,arg,0)     //Change the second argument string to a number and store it in money variable     new money = str_to_num(arg2)     //Change the users money to the amount input     g_money[target] = money     return PLUGIN_HANDLED }


EDIT: Use
Code:
public client_connect(id)
Its called whenever somebody joins. As for saving to a file, you might want to try using nVault but I would suggest just getting it done this way first.

Silencer123 07-14-2006 18:02

Re: Store custom command and value for each client which is callable and changeable
 
O_o
Thanks a very lot!
+Karma for you!
:D
Just some more things to master this plugin:
- If i write %s this is replaced with a clients name, can i
make something like %m to get replaced with users money?
- How do i make a 2nd column in the menu, where i can list prices?
- if i get the above 2 working i would love to know more about nVault :)

edit:
Code:

  case 0:
  {
  if(get_cvar_num("g_money")>8)
  {
    if(get_user_ammo(id, weapon_357, 0, 36)
    {
    client_print(id,print_chat,"[SC BUY AMMO] Your 357 Ammo Capacity is full!  (36)")
    }
    else
    {
    give_item(id,"ammo_357")
    g_money[id] -= 9
    client_print(id,print_chat,"[SC BUY AMMO] You bought six Rounds for the 357!  (-$9)")
    }
  }
  else
  {
    if(get_user_ammo(id, weapon_357, 0, 36)
    {
    client_print(id,print_chat,"[SC BUY AMMO] You do not have enough Money and your 357 Ammo Capacity is full!  ($9)  (36)")
    }
    else
    {
    client_print(id,print_chat,"[SC BUY AMMO] You do not have enough Money to buy six Rounds for the 357!  ($9)")
    }
  }
  return PLUGIN_HANDLED
  }

undefined symbol "weapon_357"
Now this one is very weird, as weapon_357 is, indeed, known as weapon_357.
I guess I used this function in a wrong way, or i need to "#include" something.

Shurik3n 07-14-2006 18:47

Re: Store custom command and value for each client which is callable and changeable
 
Quote:

Originally Posted by Silencer123
O_o
- If i write %s this is replaced with a clients name, can i
make something like %m to get replaced with users money?

Use %i as g_money is an integer. And im not sure why you used get_cvar_num("g_money") Just use if(g_money[id] >= amount).

>= means greater than or equal to. So if they have the same amout of money as the price or more it will purchase the item.

For the undefined symbol I think you need to use the weapon's ID, which is probably in an include file, instead of weapon_357 which is something you never defined and doesnt exist in an include your using.

Silencer123 07-15-2006 05:07

Re: Store custom command and value for each client which is callable and changeable
 
Mh... I remain here:
if(get_user_ammo(id, get_weaponid(weapon_357), 0, 36)
error 017: undefined symbol "weapon_357"
If the id of a weapon is always the same in one game, i may just take the time
and find out the id for every weapon?!

edit: it says argument 3 (the 0) is a mismatch.

And I still need to know how to make a second column in the menu for prices!
:>
Aaah! ingame error:


] amx_sc_buyammo
L 07/15/2006 - 11:44:00: String formatted incorrectly - parameter 4 (total 3)
L 07/15/2006 - 11:44:00: [AMXX] Run time error 25 (plugin "scbuyammo.amxx") - debug not enabled!
L 07/15/2006 - 11:44:00: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes)

EDIT: fixed. the %i did not work in the way how i used it.
Please tell me how! :o
edit: found out and it works fine :D

and I also need the menu to stay open after selecting an item.
may i add SCitemMenu(id) at the end of every case?
edit: it works

I would also apreciate a console message
"[SC BUY AMMO] Target could not be found!"
if amx_sc_buyammo_money_set targets non existing target
and
"[SC BUY AMMO] You set %i's Money to %i!"
on admins chat who executed command and
"[SC BUY AMMO] An Admin set your Money to %i!"
on clients chat who got the %i money.
edit: found it out



So far!
Now I really just need to know about that menu column and the get_user_ammo crap!


All times are GMT -4. The time now is 08:03.

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