PDA

View Full Version : Array Problem


mottzi
06-12-2010, 07:49
Hello.

I did a array:

new class[32]
When you choose the first item in my menu, 1 item in the array shout be 1.

switch(key, id)
{
case 1:
{
set_user_gravity(id, 0.5)
class[id] = 1
client_print(id, print_chat, "[FM] You are a Sonic now!");
menu_destroy(menu_class);
return PLUGIN_HANDLED;
}
}so, i registerd a event, that is called when a new round beginns. In this event i wrote:

public event_new_round(id)

{
client_print(id, print_chat, "%i <- Shout be 1 cause i set it to 1", class[id])
return PLUGIN_CONTINUE
}

BUT I GOT ALWAYS 0 instead 1 :(

can you tell me why?

Devil259
06-12-2010, 07:52
Maybe it is case 0: instead of case 1: , no ?

mottzi
06-12-2010, 07:56
No, that cant be.

Something has to be wrong with:

%i, class[id]

drekes
06-12-2010, 08:02
new class[33]

mottzi
06-12-2010, 08:09
dont work :(


here is my full code:


#include <amxmodx>
#include <amxmisc>
#include <fun>


#define PLUGIN "FutureMod"
#define VERSION "1.1"
#define AUTHOR "Mottzi"

new class[33]

public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("say /class", "change_class")
register_clcmd("say_team /class", "change_class")
register_event("HLTV", "event_new_round", "a", "1=0", "2=0")

}

public change_class(id)
{
if (!is_user_alive(id) == 1)
{
new menu_class = menu_create("\r: Choose a class!", "change_class_menu");

menu_additem(menu_class, "\wSonic", "1", 0);

menu_setprop(menu_class, MPROP_EXIT, MEXIT_ALL);

menu_display(id, menu_class, 0);
}
else
{
client_print(id, print_chat, "Only dead peaple can change their class!")
}



}

public change_class_menu(id, menu_class, item)
{


if( item == MENU_EXIT )
{
menu_destroy(menu_class);
return PLUGIN_HANDLED;
}


new data[6], iName[64];
new access, callback;

menu_item_getinfo(menu_class, item, access, data,5, iName, 63, callback);


new key = str_to_num(data);

switch(key, id)
{
case 1:
{
set_user_gravity(id, 0.5)
class[id] = 0
client_print(id, print_chat, "[FM] You are a Sonic now!");
menu_destroy(menu_class);


return PLUGIN_HANDLED;
}
}

menu_destroy(menu_class);
return PLUGIN_HANDLED;
}

public event_new_round(id)

{
client_print(id, print_chat, "%i lool", class[id])
new players[32], inum
get_players(players, inum)
for(new i = 0; i < inum, i++;)
{
client_print(id, print_chat, "%i lool", class[id])
if(class[id] == 1 )
{
set_user_health(id, 150)
set_user_gravity(id, 0.5)
}
}
return PLUGIN_CONTINUE
}

drekes
06-12-2010, 08:11
you can't use id in event_new_round, you have to loop through all the players

Edit: try this:

#include <amxmodx>
#include <amxmisc>
#include <fun>


#define PLUGIN "FutureMod"
#define VERSION "1.1"
#define AUTHOR "Mottzi"

new class[33]

public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("say /class", "change_class")
register_clcmd("say_team /class", "change_class")
register_event("HLTV", "event_new_round", "a", "1=0", "2=0")
}

public change_class(id)
{
if (!is_user_alive(id))
{
new menu_class = menu_create("\r: Choose a class!", "change_class_menu");

menu_additem(menu_class, "\wSonic", "1", 0);

menu_setprop(menu_class, MPROP_EXIT, MEXIT_ALL);

menu_display(id, menu_class, 0);
}

else
{
client_print(id, print_chat, "Only dead peaple can change their class!")
}



}

public change_class_menu(id, menu_class, item)
{


if( item == MENU_EXIT )
{
menu_destroy(menu_class);
return PLUGIN_HANDLED;
}


new data[6], iName[64];
new access, callback;

menu_item_getinfo(menu_class, item, access, data,5, iName, 63, callback);


new key = str_to_num(data);

switch(key, id)
{
case 1:
{
set_user_gravity(id, 0.5)
class[id] = 0
client_print(id, print_chat, "[FM] You are a Sonic now!");
menu_destroy(menu_class);


return PLUGIN_HANDLED;
}
}

menu_destroy(menu_class);
return PLUGIN_HANDLED;
}

public event_new_round()
{
new players[32], inum, id
get_players(players, inum)

for(new i = 0; i < inum; i++)
{
id = players[i]

if(class[id] == 1)
{
set_user_health(id, 150)
set_user_gravity(id, 0.5)
}

client_print(id, print_chat, "%i lool", class[id])
}
return PLUGIN_CONTINUE
}

mottzi
06-12-2010, 08:20
can you tell me how?

drekes
06-12-2010, 08:21
can you tell me how?

Look post above

mottzi
06-12-2010, 08:33
Thank u very much.

class[id] returns 1 now.

But why i dont get gravity and 150 hp???


if(class[id] == 1)
{
set_user_health(id, 150)
set_user_gravity(id, 0.5)
}

drekes
06-12-2010, 08:37
my guess would be that you have error logs in event round start because the player in not alive or something, check the logs and enable debug.

Bugsy
06-12-2010, 08:40
my guess would be that you have error logs in event round start because the player in not alive or something, check the logs and enable debug.

#include <amxmodx>
#include <hamsandwich>
#include <fun>

#define PLUGIN "FutureMod"
#define VERSION "1.1"
#define AUTHOR "Mottzi"

new class[33]

public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)

register_clcmd("say /class", "change_class")
register_clcmd("say_team /class", "change_class")

RegisterHam( Ham_Spawn , "player" , "fw_HamSpawn_Post" , 1 );
}

public change_class(id)
{
if ( !is_user_alive( id ) )
{
new menu_class = menu_create("\r: Choose a class!", "change_class_menu");

menu_additem( menu_class , "\wSonic" , "1" , 0 );
menu_setprop(menu_class, MPROP_EXIT, MEXIT_ALL);
menu_display(id, menu_class, 0);
}
else
{
client_print(id, print_chat, "Only dead peaple can change their class!")
}

return PLUGIN_HANDLED;
}

public change_class_menu(id, menu_class, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu_class);
return PLUGIN_HANDLED;
}

new data[6], iName[64];
new access, callback;

menu_item_getinfo(menu_class, item, access, data , 5 , iName, 63, callback);

new key = str_to_num(data);

switch( key )
{
case 1:
{
set_user_gravity(id, 0.5)
class[id] = 1 //or key will work
client_print( id , print_chat , "[FM] You are a Sonic now!" );
}
}

menu_destroy(menu_class);

return PLUGIN_HANDLED;
}

public fw_HamSpawn_Post( iPlayer )
{
if( ( class[ iPlayer ] == 1 ) && is_user_alive( iPlayer ) )
{
set_user_health( iPlayer , 150 );
set_user_gravity( iPlayer , 0.5 );

client_print( iPlayer , print_chat , "%i lool" , class[ iPlayer ] )
}
}

mottzi
06-12-2010, 08:47
no error log :( i did debug dont work..

Bugsy
06-12-2010, 08:52
Sorry, try now.

mottzi
06-12-2010, 08:56
YAAAAHHH :D WORK


nice one =) can i give u a point or something like this for that??? :D

love u

Thanks too to the other ones :D


One question: When is this event called? ham_spawn?

Bugsy
06-12-2010, 09:01
One question: When is this event called? ham_spawn?
It is called once the player is spawned (becomes alive).

mottzi
06-12-2010, 09:11
yeah cool.

This forums are pretty nice. :D thank you again :D