View Full Version : Menu and spawn stuff
So I got this menu where are 4 weapons and 1 of them is default(you spawn with it if you haven't taken another one), so I need some help with the spawn thing, so it would save the settings. I've made a menu based on the tutorial what Emp' had made. I think the spawn thing has something to do with the function, so that the WeaponName would change if the user chooses the other weapon.
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
RegisterHam(Ham_Spawn, "player", "FwdHamSpawn_Post", 1);
register_clcmd("say /weapons", "Weapons");
}
public FwdHamSpawn_Post(id)
{
SpawnedWeapon = WeaponName // Like the function SpawnedWeapon = true / false
}
public Weapons(id)
{
new menu = menu_create("\yWeapons", "menu_handler");
menu_additem(menu, "M4P1", "1", 0); // The Default weapon
menu_additem(menu, "AK47", "2", 0);
menu_additem(menu, "AWP", "3", 0);
menu_additem(menu, "Scout", "4", 0);
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_display(id, menu, 0);
}
public menu_handler(id, menu, item)
{
// Other stuff here, no point on writing the whole code here :)
}
Use a global array to keep track of everybody's chosen weapon (new g_iWeaponChoice[33], index it like: g_iWeaponChoice[id]). But, when the plugin starts, set everybody's 'choice' to which ever is default.
Could you please make an example or the thing? Because I'm rather new to this stuff and don't really know how to use the g_iWeaponChoice thing.
new g_iWeaponChoice[33]
// plugin_init()
arrayset(g_iWeaponChoice, 1, 33)
// Ham_Spawn
// Can be done several ways
switch(g_iWeaponChoice[id])
{
case 2:
{
// Second weapon
}
case 3:
{
// Third weapon
}
default:
{
// default weapon
}
}
// menu handler
// ...
g_iWeaponChoice[id] = key
It doesn't work like I need it to work, like when I die I do not spawn with the weapon I choose the last round.
It doesn't work like I need it to work, like when I die I do not spawn with the weapon I choose the last round.
To acheive faster results you will need to learn to post your full code. (No guaruntees on me being able to help you out on the Counter-Strike specific stuff).
Ok here's the full code without the modifications you told me to make.
#include <amxmodx>
#include <cstrike>
#include <fun>
#include <hamsandwich>
public plugin_init()
{
register_plugin( "Weapons", "1.0", "vL." )
RegisterHam(Ham_Spawn, "player", "Fwd_Ham_Spawn_Post", 1);
register_clcmd("say /weapons", "Weapons");
}
public Fwd_Ham_Spawn_Post(id)
{
if(is_user_connected(id) && is_user_alive(id))
{
give_item(id, "weapon_m4a1");
cs_set_user_bpammo(id, CSW_M4A1, 90);
}
return PLUGIN_HANDLED;
}
public Weapons(id)
{
new menu = menu_create("\yWeapons", "menu_handler");
menu_additem(menu, "M4A1", "1", 0); // The Default weapon
menu_additem(menu, "AK47", "2", 0);
menu_additem(menu, "AWP", "3", 0);
menu_additem(menu, "Scout", "4", 0);
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_display(id, menu, 0);
}
public menu_handler(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[6], iName[64];
new access, callback;
menu_item_getinfo(menu, item, access, data,5, iName, 63, callback);
new key = str_to_num(data);
switch(key)
{
case 1:
{
give_item(id, "weapon_m4a1");
cs_set_user_bpammo(id, CSW_M4A1, 90);
}
case 2:
{
give_item(id, "weapon_ak47");
cs_set_user_bpammo(id, CSW_AK47, 90);
}
case 3:
{
give_item(id, "weapon_awp");
cs_set_user_bpammo(id, CSW_AWP, 30);
}
case 4:
{
give_item(id, "weapon_scout");
cs_set_user_bpammo(id, CSW_SCOUT, 90);
}
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
No, show the code that doesn't work. Show what you tried. I'm not going to do it all for you.
Okay, here it is.
#include <amxmodx>
#include <cstrike>
#include <fun>
#include <hamsandwich>
new g_iWeaponChoice[33]
public plugin_init()
{
register_plugin( "Weapons", "1.0", "vL." )
arrayset(g_iWeaponChoice, 1, 33)
RegisterHam(Ham_Spawn, "player", "Fwd_Ham_Spawn_Post", 1);
register_clcmd("say /weapons", "Weapons");
}
public Fwd_Ham_Spawn_Post(id)
{
if(is_user_connected(id) && is_user_alive(id))
{
switch(g_iWeaponChoice[id])
{
case 2:
{
give_item(id, "weapon_ak47");
cs_set_user_bpammo(id, CSW_AK47, 90);
}
case 3:
{
give_item(id, "weapon_awp");
cs_set_user_bpammo(id, CSW_AWP, 30);
}
case 4:
{
give_item(id, "weapon_scout");
cs_set_user_bpammo(id, CSW_SCOUT, 90);
}
default:{
give_item(id, "weapon_m4a1");
cs_set_user_bpammo(id, CSW_M4A1, 90);
}
}
}
return PLUGIN_HANDLED;
}
public Weapons(id)
{
new menu = menu_create("\yWeapons", "menu_handler");
menu_additem(menu, "M4A1", "1", 0); // The Default weapon
menu_additem(menu, "AK47", "2", 0);
menu_additem(menu, "AWP", "3", 0);
menu_additem(menu, "Scout", "4", 0);
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_display(id, menu, 0);
}
public menu_handler(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[6], iName[64];
new access, callback;
menu_item_getinfo(menu, item, access, data,5, iName, 63, callback);
new key = str_to_num(data);
g_iWeaponChoice[id] = key
switch(key)
{
case 1:
{
give_item(id, "weapon_m4a1");
cs_set_user_bpammo(id, CSW_M4A1, 90);
}
case 2:
{
give_item(id, "weapon_ak47");
cs_set_user_bpammo(id, CSW_AK47, 90);
}
case 3:
{
give_item(id, "weapon_awp");
cs_set_user_bpammo(id, CSW_AWP, 30);
}
case 4:
{
give_item(id, "weapon_scout");
cs_set_user_bpammo(id, CSW_SCOUT, 90);
}
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
Looks fine to me (well, you don't need the is_user_connected() check but that won't affect anything).
Maybe it's something with CS that I'm not familiar with.
But are you aware of the CSDM system? That how it saves the settings when you choose the guns and press "I want this every round" - or something like hat
Use array.
new g_Autoaccept[33]
Save there the choosed wep number.
Could you make an example maybe?
Use array.
new g_Autoaccept[33]
Save there the choosed wep number.
Did you even read the code? It does this. Maybe not literally but it does it nonetheless.
@vL. It's time to debug it.
Debug what, if you mean pluginame.amxx debug - then thats enabled and it gives no errors.
Debug what, if you mean pluginame.amxx debug - then thats enabled and it gives no errors.
Nope. Not what I meant.
Well could you tell me what you meant then?
Did you even read the code? It does this. Maybe not literally but it does it nonetheless.
It's hard to understand which version he uses, because the last one does this but building on his question he doesn't use it.
Well could you tell me what you meant then?
Firts sentence here:
http://en.wikipedia.org/wiki/Debug#Various_debugging_techniques
Ohh yes thanks fysiks, got it to work, there was a little code misplacing or something like that.
vBulletin® v3.8.7, Copyright ©2000-2024, vBulletin Solutions, Inc.