View Full Version : Array Problem
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 ?
No, that cant be.
Something has to be wrong with:
%i, class[id]
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
}
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
}
can you tell me how?
Look post above
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)
}
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.
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 ] )
}
}
no error log :( i did debug dont work..
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?
One question: When is this event called? ham_spawn?
It is called once the player is spawned (becomes alive).
yeah cool.
This forums are pretty nice. :D thank you again :D
vBulletin® v3.8.7, Copyright ©2000-2024, vBulletin Solutions, Inc.