I am making my first actual plugin, but I a having a bit trouble with it.
What is wrong with this is that nothing of the stuff I want to set is being set. At firs I thought it was the way I picked the player index randomly, but the client_print is working. I do get the message "Health added", and my name changes as i want it to change. It has to be the natives, or the way I am using the natives which is wrong.
The plugin isn't finished, so I do indeed know that my name wont change back.
PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <hamsandwich>
#include <fun>
//cvars
new pcvarHealth
new pcvarArmor
new pcvarSpeed
new pcvarGrav
new pcvarAnnounce
new pcvarPrefix
new RandomNum
public plugin_init()
{
register_plugin("Random Super player", "1.0", "Jelle")
//cvars
pcvarHealth = register_cvar("super_health", "200")
pcvarArmor = register_cvar("super_armor", "200")
pcvarSpeed = register_cvar("super_speed", "300")
pcvarGrav = register_cvar("super_gravity", "0.8")
pcvarAnnounce = register_cvar("super_announce", "1")
pcvarPrefix = register_cvar("super_prefix", "1")
//events
register_event("HLTV", "round_new", "a", "1=0", "2=0")
register_logevent("round_end", 2, "1=Round_End")
}
public round_new()
{
//get random playerid
RandomNum = random_num(1, get_playersnum())
//set super player stuff
set_user_health(RandomNum, get_pcvar_num(pcvarHealth))
client_print(RandomNum, print_chat, "Health added")
set_user_armor(RandomNum, get_pcvar_num(pcvarArmor))
set_user_maxspeed(RandomNum, get_pcvar_float(pcvarSpeed))
set_user_gravity(RandomNum, get_pcvar_float(pcvarGrav))
//get super players name
new PlayerName[64]
get_user_name(RandomNum, PlayerName, 63)
//Announce that player is a super player
if ( get_pcvar_num(pcvarAnnounce) )
{
client_print(0, print_chat, "Watch out! %s has become a super player!", PlayerName)
}
//set new name with prefix
if ( get_pcvar_num(pcvarPrefix) )
{
new prefix[] = "[Super]"
new FullName[64]
formatex(FullName, charsmax(FullName), "%s %s", prefix, PlayerName)
set_user_info(RandomNum, "name", FullName)
}
}
public round_end()
{
//if user is dead then just return
if ( !is_user_alive(RandomNum) ) return
//if user has more than 100 hp then reset to 100
if ( get_user_health(RandomNum) > 100 )
{
set_user_health(RandomNum, 100)
}
//if user has more than 100 ap then reset to 100
if ( get_user_armor(RandomNum) > 100 )
{
set_user_armor(RandomNum, 100)
}
//reset speed and gravity
set_user_maxspeed(RandomNum, 240.0)
set_user_gravity(RandomNum, 1.0)
}
When I disconnect from the server (I am the only one in it) it gives me this error:
Code:
Dropped [Super] [RD] Jelle from server
Reason: Kicked
L 01/13/2011 - 00:04:58: [FUN] Invalid player 1
L 01/13/2011 - 00:04:58: [AMXX] Displaying debug trace (plugin "super_player.amxx")
L 01/13/2011 - 00:04:58: [AMXX] Run time error 10: native error (native "set_user_health")
L 01/13/2011 - 00:04:58: [AMXX] [0] super_player.sma::round_new (line 40)
I assume this is because it can't modify on a player index which isn't connected.
__________________