Raised This Month: $ Target: $400
 0% 

hp/ap/speed/grav wont set


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 01-12-2011 , 18:07   hp/ap/speed/grav wont set
Reply With Quote #1

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(1get_playersnum())
 
 
//set super player stuff
 
set_user_health(RandomNumget_pcvar_num(pcvarHealth))
 
client_print(RandomNumprint_chat"Health added")
 
set_user_armor(RandomNumget_pcvar_num(pcvarArmor))
 
set_user_maxspeed(RandomNumget_pcvar_float(pcvarSpeed))
 
set_user_gravity(RandomNumget_pcvar_float(pcvarGrav))
 
 
//get super players name
 
new PlayerName[64]
 
get_user_name(RandomNumPlayerName63)
 
 
//Announce that player is a super player
 
if ( get_pcvar_num(pcvarAnnounce) )
 {
  
client_print(0print_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(FullNamecharsmax(FullName), "%s %s"prefixPlayerName)
  
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(RandomNum100)
 }
 
 
//if user has more than 100 ap then reset to 100
 
if ( get_user_armor(RandomNum) > 100 )
 {
  
set_user_armor(RandomNum100)
 }
 
 
//reset speed and gravity
 
set_user_maxspeed(RandomNum240.0)
 
set_user_gravity(RandomNum1.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.
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
Kreation
Veteran Member
Join Date: Jan 2010
Location: Illinois
Old 01-12-2011 , 18:12   Re: hp/ap/speed/grav wont set
Reply With Quote #2

IMO, that's a very inefficient way to set all that. I mean with the 'RandomNum' thing you have going on.
Try this stock I have sitting around.

Code:
new id = get_random_player( ); stock get_random_player( ) {     /*     * a - Don't return dead players     * b - Don't return alive players     * c - Skip bots     * d - Skip real players     * e - Match with passed team     * f - Match with part of name     * g - Ignore case sensitivity     * h - Skip HLTV     */         new iPlayers[32], iTotal;     get_players( iPlayers, iTotal, "ah" );         if( !iTotal ) return 0;         return iPlayers[random( iTotal )]; }

Other than that, check is_user_alive and it shouldn't give you run time 10.
__________________
Hi.
Kreation is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 01-12-2011 , 18:16   Re: hp/ap/speed/grav wont set
Reply With Quote #3

It may be an ineffective way of doing it, but shouldn't it work anyway? As it changes my name, it should be working.

I will try it now though. I also make an alive check.
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
Kreation
Veteran Member
Join Date: Jan 2010
Location: Illinois
Old 01-12-2011 , 18:22   Re: hp/ap/speed/grav wont set
Reply With Quote #4

The alive check will definitely get rid of the run time error. It's happened to me before.
__________________
Hi.
Kreation is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 01-12-2011 , 18:23   Re: hp/ap/speed/grav wont set
Reply With Quote #5

It did get rid of the error. But after using the stock you provided me nothing happens at all. My name doesn't change, nor do I get anything printed in my chat. And now there is no error at all.

EDIT:
I removed the alive check again and now I get a new error. This is by using the stock you provided:

Code:
L 01/13/2011 - 00:24:19: [FUN] Player out of range (0)
L 01/13/2011 - 00:24:19: [AMXX] Displaying debug trace (plugin "super_player.amxx")
L 01/13/2011 - 00:24:19: [AMXX] Run time error 10: native error (native "set_user_health")
L 01/13/2011 - 00:24:19: [AMXX]    [0] super_player.sma::round_new (line 41)
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 01-12-2011 , 18:50   Re: hp/ap/speed/grav wont set
Reply With Quote #6

You also have to check if if get_random_player() doesn't return 0.
If it does, there is no alive player.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
matsi
Thinkosaur
Join Date: Sep 2006
Old 01-13-2011 , 10:18   Re: hp/ap/speed/grav wont set
Reply With Quote #7

Quote:
Originally Posted by Jelle View Post
It did get rid of the error. But after using the stock you provided me nothing happens at all. My name doesn't change, nor do I get anything printed in my chat. And now there is no error at all.

EDIT:
I removed the alive check again and now I get a new error. This is by using the stock you provided:

Code:
L 01/13/2011 - 00:24:19: [FUN] Player out of range (0)
L 01/13/2011 - 00:24:19: [AMXX] Displaying debug trace (plugin "super_player.amxx")
L 01/13/2011 - 00:24:19: [AMXX] Run time error 10: native error (native "set_user_health")
L 01/13/2011 - 00:24:19: [AMXX]    [0] super_player.sma::round_new (line 41)
I added alive check on your original code and tested, works fine without any errors. I also tested your code with the stock and no errors.

ps. If you have been selected as super player twice you will have two tags. So you should reset old super players name before selecting new.
matsi is offline
Old 01-13-2011, 10:39
meTaLiCroSS
This message has been deleted by meTaLiCroSS. Reason: wrong thread
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 01-13-2011 , 14:58   Re: hp/ap/speed/grav wont set
Reply With Quote #8

Quote:
Originally Posted by matsi View Post
I added alive check on your original code and tested, works fine without any errors. I also tested your code with the stock and no errors.

ps. If you have been selected as super player twice you will have two tags. So you should reset old super players name before selecting new.
That is odd. It doesn't work at all for me.

I do indeed know that it doesn't reset the name. I also wrote that in the start of the topic.

Then it must be my server which wont work properly. Also strange that I get no errors or anything.
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
Elusive138
Senior Member
Join Date: Dec 2010
Old 01-13-2011 , 15:14   Re: hp/ap/speed/grav wont set
Reply With Quote #9

Quote:
Originally Posted by Jelle View Post
That is odd. It doesn't work at all for me.

I do indeed know that it doesn't reset the name. I also wrote that in the start of the topic.

Then it must be my server which wont work properly. Also strange that I get no errors or anything.
Try a clean AMXX install... might be something wrong with your modules or another plugin interfering.
Elusive138 is offline
Kreation
Veteran Member
Join Date: Jan 2010
Location: Illinois
Old 01-13-2011 , 15:14   Re: hp/ap/speed/grav wont set
Reply With Quote #10

I don't think it matters, but why do you have ham included when you don't use it.
__________________
Hi.
Kreation is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:56.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode