AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   hp/ap/speed/grav wont set (https://forums.alliedmods.net/showthread.php?t=147715)

Jelle 01-12-2011 18:07

hp/ap/speed/grav wont set
 
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.

Kreation 01-12-2011 18:12

Re: hp/ap/speed/grav wont set
 
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.

Jelle 01-12-2011 18:16

Re: hp/ap/speed/grav wont set
 
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.

Kreation 01-12-2011 18:22

Re: hp/ap/speed/grav wont set
 
The alive check will definitely get rid of the run time error. It's happened to me before.

Jelle 01-12-2011 18:23

Re: hp/ap/speed/grav wont set
 
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)


drekes 01-12-2011 18:50

Re: hp/ap/speed/grav wont set
 
You also have to check if if get_random_player() doesn't return 0.
If it does, there is no alive player.

matsi 01-13-2011 10:18

Re: hp/ap/speed/grav wont set
 
Quote:

Originally Posted by Jelle (Post 1392329)
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.

Jelle 01-13-2011 14:58

Re: hp/ap/speed/grav wont set
 
Quote:

Originally Posted by matsi (Post 1392705)
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.

Elusive138 01-13-2011 15:14

Re: hp/ap/speed/grav wont set
 
Quote:

Originally Posted by Jelle (Post 1392879)
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.

Kreation 01-13-2011 15:14

Re: hp/ap/speed/grav wont set
 
I don't think it matters, but why do you have ham included when you don't use it.


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

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