AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   AMXX Errors (https://forums.alliedmods.net/showthread.php?t=187621)

Waleed 06-15-2012 16:39

AMXX Errors
 
Hey there,I need a little help,I checked everything twice but couldn't figure out whats the problem

These are the errors: ( Generated in Console )

L 06/16/2012 - 01: 31:18: [FUN] Invalid player 1
L 06/16/2012 - 01: 31:18: [AMXX] Displaying debug trace (plugin "adminmode.amxx")
L 06/16/2012 - 01: 31:18: [AMXX] Run time error 10: native error (native "set_user_health")
L 06/16/2012 - 01: 31:18: [AMXX] [0] adminmode.sma::ClientSpawn (line 21)

"set_user_health" is a native from fun.inc but I am including fun,If I change it to fun.inc
It displays the same error.Help please

I am using the following code:

Code:

if (is_user_alive(id))
{
set_user_health(id, 200)
cs_set_user_armor(id, 300, CS_ARMOR_VESTHELM) // For Armor,You know that!
}


Liverwiz 06-15-2012 16:49

Re: AMXX Errors
 
check is_user_connected(id)

Waleed 06-15-2012 17:04

Re: AMXX Errors
 
I am checking:
Code:

is_user_admin(id)
Is it okay or do I have to check for user connection too O_O ?

Aooka 06-15-2012 17:19

Re: AMXX Errors
 
Test this :

Code:
#include < amxmodx > #include < hamsandwich > #include < cstrike > #include < fun > public plugin_init( ) {     register_plugin( "test" , "1.0" , "Aooka" );         RegisterHam( Ham_Spawn , "player" , "Fw_HamSpawn" , true ); } public Fw_HamSpawn( id ) {     if( is_user_alive( id ) )     {         set_user_health( id , 200 );         cs_set_user_armor( id , 300 , CS_ARMOR_VESTHELM );     }     return 0; }

Aooka 06-15-2012 17:20

Re: AMXX Errors
 
Quote:

Originally Posted by Waleed (Post 1729445)
I am checking:
Code:

is_user_admin(id)
Is it okay or do I have to check for user connection too O_O ?

not necessarily

fysiks 06-15-2012 19:43

Re: AMXX Errors
 
Quote:

Originally Posted by Liverwiz (Post 1729433)
check is_user_connected(id)

You don't need to check for connected if you are only checking for alive.

Quote:

Originally Posted by Waleed (Post 1729445)
I am checking:
Code:

is_user_admin(id)
Is it okay or do I have to check for user connection too O_O ?

I believe you do have to check connection for using that function. You can test it out. Just try it on an empty slot. If you get a runtime error then you need to check if they are connected first. If it simply returns false without errors then you don't need the extra check. It all really comes down to how get_user_flags() works.

Waleed 06-16-2012 04:03

Re: AMXX Errors
 
Why everybody use:
Code:

fw_playerspawn //fw_ before this function
I have been using only
Code:

PlayerSpawn
PlayerAlive  // No fw_ before calling functions

Will it cause any error or is it good?

Aooka 06-16-2012 05:37

Re: AMXX Errors
 
Quote:

Originally Posted by Waleed (Post 1729646)
Why everybody use:
Code:

fw_playerspawn //fw_ before this function
I have been using only
Code:

PlayerSpawn
PlayerAlive  // No fw_ before calling functions

Will it cause any error or is it good?

We use fw_MyFunction or Fw_MyFunction or FwMyFunction etc ...
Because the function is a forward.

So what is a forward ?
Hum, it's a special function in fact.
Take a look just here : http://www.amxmodx.org/funcwiki.php?go=module&id=24

You see that for instance :

Quote:

/**
* Description: Normally called whenever an entity dies.
* Forward params: function(this, idattacker, shouldgib)
* Return type: None.
* Execute params: ExecuteHam(Ham_Killed, this, idattacker, shouldgib);
*/
Ham_Killed,
Here :
Quote:

Forward params: function(this, idattacker, shouldgib)
I don't know how to explain ... LoL

See that :wink:

<VeCo> 06-16-2012 06:34

Re: AMXX Errors
 
get_user_flags() doesn't check if the user is connected, so yeah, you should use is_user_connected before using get_user_flags()/is_user_admin() (or any other stock that uses get_user_flags() native) of you aren't sure if the user is in the server:

PHP Code:

tatic cell AMX_NATIVE_CALL get_user_flags(AMX *amxcell *params/* 2 param */
{
int index params[1];
 
if (
index || index gpGlobals->maxClients)
{
LogError(amxAMX_ERR_NATIVE"Invalid player id %d"index);
return 
0;
}
 
int id params[2];
 
if (
id 0)
 
id 0;
if (
id 31)
 
id 31;
 
 return 
GET_PLAYER_POINTER_I(index)->flags[id];



The name of the function doesn't matter, it's more depending on your choice and style.

hornet 06-16-2012 22:17

Re: AMXX Errors
 
Quote:

Originally Posted by Waleed (Post 1729646)
Why everybody use:
Code:

fw_playerspawn //fw_ before this function
I have been using only
Code:

PlayerSpawn
PlayerAlive  // No fw_ before calling functions

Will it cause any error or is it good?

It doesn't matter what you call your function name so long as it doesn't pre-exist. Everyone has there own style, quite often based on the type / module the function / foward is or is using.


All times are GMT -4. The time now is 13:25.

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