|
Member
|

10-11-2010
, 22:23
Help with my classes script
|
#1
|
So, I made a simple mod, taking a lot of stuff from some other mods I found and the menu tutorial....and it compiles and works fine except for one little thing: The system I want is one where once a player chooses his or her class, it'll stay at that class for the rest of the game and they won't have to repick it every round. Meaning if they die they automatically get the items from the class back when they respawn. But right now it makes them repick it. And BTW I know the code doesn't look pretty and it's not really well coded, but it doesn't really matter to me right now. I have done java and c# programming before so I know some basics, but I don't really know what I'm doing with pawn so I'm kind of afraid to modify the code a lot from the original plugin I ripped it from (I think startweapons)...if you could help me make it prettier too that'd be cool.
Code:
#include <amxmodx>
#include <fun>
#include <engine>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>
#define TEAM_T 1
#define TEAM_CT 2
new cclass = 0;
public plugin_modules() {
require_module("fun")
require_module("engine")
require_module("cstrike")
}
public plugin_init()
{
register_plugin("StartingClasses", "1.0", "iamSTEVE")
register_cvar("AMX_CLASS1", "strip weapon_knife weapon_deagle ammo_50ae ammo_50ae ammo_50ae ammo_50ae ammo_50ae weapon_scout ammo_762nato weapon_hegrenade weapon_flashbang"); //sniper
register_cvar("AMX_CLASS2", "strip weapon_knife weapon_m3 ammo_buckshot ammo buckshot ammmo buckshot weapon_aug ammo_556nato ammo_556nato ammo_556nato ammo_556nato weapon_hegrenade weapon_flashbang"); //long range assault
register_cvar("AMX_CLASS3", "strip weapon_knife weapon_m3 ammo_buckshot ammo_buckshot ammo_buckshot ammo_buckshot ammo_buckshot weapon_m4a1 ammo_556nato ammo_556nato ammo_556nato ammo_556nato ammo_556nato weapon_hegrenade weapon_flashbang"); //regular assault
register_cvar("AMX_CLASS4", "strip weapon_knife weapon_m3 ammo_buckshot ammo_buckshot ammo_buckshot ammo_buckshot ammo_buckshot weapon_ak47 ammo_762nato ammo_762nato ammo_762nato ammo_762nato ammo_762nato weapon_hegrenade weapon_flashbang"); //ak47 assault
register_cvar("AMX_CLASS5", "strip weapon_knife weapon_deagle ammo_50ae ammo_50ae ammo_50ae ammo_50ae ammo_50ae weapon_mp5navy ammo_9mm ammo_9mm ammo_9mm ammo_9mm ammo_9mm weapon_hegrenade weapon_flashbang"); //smg rusher
register_cvar("AMX_CLASS6", "strip weapon_knife weapon_elite ammo_9mm ammo_9mm weapon_awp ammo_338magnum weapon_hegrenade weapon_flashbang"); //awp sniper
register_cvar("AMX_CLASS7", "strip weapon_knife weapon_deagle ammo_50ae ammo_50ae ammo_50ae ammo_50ae ammo_50ae weapon_p90 ammo_57mm ammo_57mm ammo_57mm ammo_57mm ammo_57mm weapon_hegrenade weapon_flashbang"); //p90 rusher
register_cvar("AMX_CLASS8", "strip weapon_knife weapon_deagle ammo_50ae ammo_50ae ammo_50ae ammo_50ae ammo_50ae weapon_sg552 ammo_556nato ammo_556nato ammo_556nato ammo_556nato ammo_556nato weapon_hegrenade weapon_flashbang"); //sg man
register_cvar("AMX_CLASS9", "strip weapon_knife weapon_deagle ammo_50ae ammo_50ae ammo_50ae ammo_50ae ammo_50ae weapon_ump45 ammo_45acp ammo_45acp ammo_45acp ammo_45acp ammo_45acp weapon_hegrenade weapon_flashbang"); //UMP
register_cvar("AMX_CLASS10", "strip weapon_knife weapon_deagle ammo_50ae ammo_50ae ammo_50ae ammo_50ae ammo_50ae ammo_50ae ammo_50ae ammo_50ae ammo_50ae ammo_50ae"); //VIP
register_clcmd("change_class", "MakeMenu");
register_event("ResetHUD", "event_spawn", "b")
}
public event_spawn(id) {
if (!is_user_alive(id))
return PLUGIN_CONTINUE;
new team = get_user_team(id);
if (team != TEAM_T && team != TEAM_CT)
return PLUGIN_CONTINUE;
new mapname[32];
get_mapname(mapname, 32);
if (contain(mapname, "awp") != -1 || contain(mapname, "scout") != -1 || contain(mapname, "aim") != -1)
return PLUGIN_CONTINUE;
giveDefault(id, (team == TEAM_T) ? true: false, cclass);
return PLUGIN_CONTINUE
}
public MakeMenu(id)
{
new menu = menu_create("\rChoose your class:", "menu_handler");
menu_additem(menu, "\wOpTic", "1", 0);
menu_additem(menu, "\wLong Range Assault", "2", 0);
menu_additem(menu, "\wCounter Terrorist Assault", "3", 0);
menu_additem(menu, "\wTerrorist Assault", "4", 0);
menu_additem(menu, "\wMP5 Rusher", "5", 0);
menu_additem(menu, "\w.50cal Sniper", "6", 0);
menu_additem(menu, "\wP90 Rusher", "7", 0);
menu_additem(menu, "\wTerrorist Marksman", "8", 0);
menu_additem(menu, "\wUltra Tryhard", "9", 0);
menu_additem(menu, "\wVIP", "10", 0);
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_display(id, menu, 0);
}
//okay, we showed them the menu, now lets handle it (looking back at menu_create, we are going to use that function)
public menu_handler(id, menu, item)
{
//we don't want to deal with them if they exited a menu
if( item == MENU_EXIT )
{
menu_destroy(menu);
//Note that you will want to destroy the menu after they do something
return PLUGIN_HANDLED;
}
//now lets create some variables that will give us information about the menu and the item that was pressed/chosen
new data[6], iName[64];
new access, callback;
//heres the function that will give us that information (since it doesnt magicaly appear)
menu_item_getinfo(menu, item, access, data,5, iName, 63, callback);
//what the data for the menu item was
new key = str_to_num(data);
cclass = key;
giveDefault(id, (get_user_team(id) == TEAM_T) ? true: false, key);
menu_destroy(menu);
return PLUGIN_HANDLED;
}
public giveDefault(id, terrorist, class) {
new bool:hasBomb = false;
new stuff[256];
switch(class) {
case 0 : { //we have not chosen the class yet
MakeMenu(id);
return PLUGIN_CONTINUE;
}
case 1 : {
get_cvar_string("AMX_CLASS1", stuff, 255);
}
case 2 : {
get_cvar_string("AMX_CLASS2", stuff, 255);
}
case 3 : {
get_cvar_string("AMX_CLASS3", stuff, 255);
}
case 4 : {
get_cvar_string("AMX_CLASS4", stuff, 255);
}
case 5 : {
get_cvar_string("AMX_CLASS5", stuff, 255);
}
case 6 : {
get_cvar_string("AMX_CLASS6", stuff, 255);
}
case 7 : {
get_cvar_string("AMX_CLASS7", stuff, 255);
}
case 8 : {
get_cvar_string("AMX_CLASS8", stuff, 255);
}
case 9 : {
get_cvar_string("AMX_CLASS9", stuff, 255);
}
case 10 : {
get_cvar_string("AMX_CLASS10", stuff, 255);
}
}
if (containi(stuff, "strip") != -1) {
strip_user_weapons(id)
if (hasBomb) {
give_item(id, "weapon_c4")
cs_set_user_plant(id)
}
replace(stuff, 255, "strip", "")
}
if (class != 10) {
give_item(id, "item_assaultsuit");
}
if (terrorist) {
give_item(id, "weapon_c4");
cs_set_user_plant(id)
} else {
cs_set_user_defuse(id);
}
new parsedParams, arg[256]
do {
parsedParams = parse(stuff, arg, 255)
if (parsedParams == 1 && !is_user_bot(id)) {
replace(stuff, 255, arg, "")
give_item(id, arg)
}
} while (parsedParams == 1)
return PLUGIN_HANDLED;
}
It compiles with warnings which I don't care about, loose indentation, whatever. But runtime error occurs at line 88 and 144 and is embedded in 40 (where it calls on the method). What this does right now is bring up the menu everytime you respawn, so it still kinda works, just not like I'd like it to. And this doesn't make sense to me at all cause both line 88 and 144 are just variable declarations, which only fuck up when it puts the value of cclass into the param class. Which makes no fucking sense...
Last edited by iamSTEVE; 10-11-2010 at 22:48.
|
|