AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Run time error 10: native error (native "get_user_stats") (https://forums.alliedmods.net/showthread.php?t=136028)

GarbageBox 08-22-2010 05:19

Run time error 10: native error (native "get_user_stats")
 
Code:

                new targetid, body
                get_user_aiming(id, targetid, body, 9999)
                new SzRankPos, SzRankMax, SzABC[8]
                SzRankPos = get_user_stats(targetid, SzABC, SzABC)
                SzRankMax = get_statsnum()
                set_hudmessage(10, 10, 50, -1.00, 0.63, 0, 1.0, 1.0, 0.1, 0.2, -1)
                ShowSyncHudMsg(id, hudsync, "His Rank %d/%d", SzRankPos, SzRankMax)

This is a easy code, but I get error when the server run a period time.
Not crash server.
Run time error 10: native error (native "get_user_stats")
How can I fix it?

RedRobster 08-22-2010 10:18

Re: Run time error 10: native error (native "get_user_stats")
 
What is the entire error?

Hunter-Digital 08-22-2010 16:18

Re: Run time error 10: native error (native "get_user_stats")
 
I'm most certain it's the "invalid player #??" one.

In your code, you don't even check if targetid exists before doing something. Check if targetid is a player... with 1 <= targetid <= get_maxplayers() (cache the value in a global variable set in plugin_init() )

GarbageBox 08-22-2010 23:16

Re: Run time error 10: native error (native "get_user_stats")
 
Quote:

Originally Posted by RedRobster (Post 1278735)
What is the entire error?

L 08/23/2010 - 11:13:39: [CSX] Player out of range (7X)
L 08/23/2010 - 11:13:39: [AMXX] Displaying debug trace (plugin "SPEC+Hud+Message.amxx")
L 08/23/2010 - 11:13:39: [AMXX] Run time error 10: native error (native "get_user_stats")
L 08/23/2010 - 11:13:39: [AMXX] [0] Rank.sma::DHM (line 47)

Quote:

Originally Posted by Hunter-Digital (Post 1279052)
I'm most certain it's the "invalid player #??" one.

In your code, you don't even check if targetid exists before doing something. Check if targetid is a player... with 1 <= targetid <= get_maxplayers() (cache the value in a global variable set in plugin_init() )

What do you mean?

Hunter-Digital 08-22-2010 23:26

Re: Run time error 10: native error (native "get_user_stats")
 
What do you mean what do I mean ?

That's the error, "Player out of range", it triggers because you don't check if get_user_aiming() actually hits a player or even hits anything at all ! get_user_stats() only works on players.

GarbageBox 08-22-2010 23:55

Re: Run time error 10: native error (native "get_user_stats")
 
Quote:

Originally Posted by Hunter-Digital (Post 1279395)
What do you mean what do I mean ?

That's the error, "Player out of range", it triggers because you don't check if get_user_aiming() actually hits a player or even hits anything at all ! get_user_stats() only works on players.

Then I need to change or add what in my code?

nikhilgupta345 08-23-2010 00:04

Re: Run time error 10: native error (native "get_user_stats")
 
maybe is_user_alive(targetid)

or

is_user_connected(targetid)

GarbageBox 08-23-2010 03:07

Re: Run time error 10: native error (native "get_user_stats")
 
Fixed, thanks all.


All times are GMT -4. The time now is 21:55.

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