PDA

View Full Version : Menu and spawn stuff


vL.
06-10-2010, 20:36
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 :)
}

fysiks
06-10-2010, 20:45
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.

vL.
06-10-2010, 20:56
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.

fysiks
06-10-2010, 23:12
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

vL.
06-11-2010, 04:41
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.

fysiks
06-11-2010, 17:06
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).

vL.
06-11-2010, 18:05
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;
}

fysiks
06-11-2010, 19:10
No, show the code that doesn't work. Show what you tried. I'm not going to do it all for you.

vL.
06-11-2010, 19:33
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;
}

vL.
06-14-2010, 01:38
Fysik any luck?

fysiks
06-14-2010, 01:56
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.

vL.
06-14-2010, 02:05
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

Kryzu
06-14-2010, 16:54
Use array.

new g_Autoaccept[33]

Save there the choosed wep number.

vL.
06-14-2010, 17:10
Could you make an example maybe?

fysiks
06-14-2010, 18:32
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.

vL.
06-15-2010, 01:29
Debug what, if you mean pluginame.amxx debug - then thats enabled and it gives no errors.

fysiks
06-15-2010, 01:44
Debug what, if you mean pluginame.amxx debug - then thats enabled and it gives no errors.

Nope. Not what I meant.

vL.
06-15-2010, 02:01
Well could you tell me what you meant then?

Kryzu
06-15-2010, 05:21
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.

fysiks
06-15-2010, 17:50
Well could you tell me what you meant then?


Firts sentence here:
http://en.wikipedia.org/wiki/Debug#Various_debugging_techniques

vL.
06-18-2010, 21:46
Ohh yes thanks fysiks, got it to work, there was a little code misplacing or something like that.