AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Trying to fix these 2 persistent errors (https://forums.alliedmods.net/showthread.php?t=147842)

thatdarnkid 01-14-2011 19:44

Trying to fix these 2 persistent errors
 
So I'm working on my rebuild/error-free (hopefully) version of noodleboy347's Premium Mod v1.14 and I keep running into these 2 errors:

Code:

25:44: [SM] Native "GetEntProp" reported: Entity -1 (-1) is invalid
L 01/14/2011 - 18:25:44: [SM] Displaying call stack trace for plugin "premium.smx":
L 01/14/2011 - 18:25:44: [SM]  [0]  Line 692, C:\Users\User\Desktop\TF2 Stuff\Compiler\scripting\premium.sp::Premium()
L 01/14/2011 - 18:25:44: [SM]  [1]  Line 204, C:\Users\User\Desktop\TF2 Stuff\Compiler\scripting\premium.sp::Player_Spawn()

Here's the entirety of the plugin: http://pastebin.com/HXAuHKui

I've been talking to Toazron over Steam for the past...ohh....2 weeks or so, and he's really helped me out, not only with some things related to this plugin, but also with things like setting up a menu with his basic donator interface.

Now, here's the thing. I appreciate you guys posting your little tidbits of help here and there, but when it comes to coding.....I doubt I could even be called a "beginner". So I would greatly appreciate it if someone could look over the plugin, and help me out big time by either:

- Posting the fixed code so that I can copy/paste it into the plugin
or
- Copy/pasting the above pastebin contents into a new pastebin, but with the code that's causing those 2 errors fixed.

Major MAJOR credit will be given once I make sure the plugin is 100% error free, and upload it to the New Plugins section.

dirtyminuth 01-14-2011 20:26

Re: Trying to fix these 2 persistent errors
 
It would help if you highlighted the stack trace function lines.

Regardless, I'd bet that the client has an invalid slot 0 weapon and the following line is executed:
PHP Code:

SetEntProp(GetPlayerWeaponSlot(client0), Prop_Send"m_iClip1"GetEntProp(GetPlayerWeaponSlot(client0), Prop_Send"m_iClip1") + cClip); 


thatdarnkid 01-14-2011 20:37

Re: Trying to fix these 2 persistent errors
 
Quote:

Originally Posted by dirtyminuth (Post 1393782)
It would help if you highlighted the stack trace function lines.

Regardless, I'd bet that the client has an invalid slot 0 weapon and the following line is executed:
PHP Code:

SetEntProp(GetPlayerWeaponSlot(client0), Prop_Send"m_iClip1"GetEntProp(GetPlayerWeaponSlot(client0), Prop_Send"m_iClip1") + cClip); 


Hmm...what exactly would an invalid slot 0 weapon be? I'm not exactly sure what that means, but it intrigues me...

EDIT: I just changed my original post. I changed the code tags to php tags.

dirtyminuth 01-14-2011 21:02

Re: Trying to fix these 2 persistent errors
 
Quote:

Originally Posted by thatdarnkid (Post 1393790)
Hmm...what exactly would an invalid slot 0 weapon be? I'm not exactly sure what that means, but it intrigues me...

EDIT: I just changed my original post. I changed the code tags to php tags.

Well, from the code I quoted earlier, you call:
PHP Code:

GetEntProp(GetPlayerWeaponSlot(client0), Prop_Send"m_iClip1"

Inside that, you call:
PHP Code:

GetPlayerWeaponSlot(client0

If GetPlayerWeaponSlot returns -1, SM will throw an error like you're experiencing.

thatdarnkid 01-14-2011 21:16

Re: Trying to fix these 2 persistent errors
 
Quote:

Originally Posted by dirtyminuth (Post 1393797)
Well, from the code I quoted earlier, you call:
PHP Code:

GetEntProp(GetPlayerWeaponSlot(client0), Prop_Send"m_iClip1"

Inside that, you call:
PHP Code:

GetPlayerWeaponSlot(client0

If GetPlayerWeaponSlot returns -1, SM will throw an error like you're experiencing.

OHH. See, little gears inside my head are starting to turn and I'm starting to understand this stuff.

But what I don't get....is what item would count as -1...

Slot 0 is primary, slot 1 is secondary and slot 2 is melee, correct? What could be making SM throw that error?....

Peace-Maker 01-14-2011 21:38

Re: Trying to fix these 2 persistent errors
 
If the player doesn't carry a primary/secondary or knife, it returns -1 for that weaponindex.

PHP Code:

GetUserFlagBits(client) && PREMIUMFLAG 

should be
PHP Code:

GetUserFlagBits(client) & PREMIUMFLAG 

it's the bitwise AND.

dirtyminuth 01-14-2011 21:40

Re: Trying to fix these 2 persistent errors
 
Quote:

Originally Posted by thatdarnkid (Post 1393800)
OHH. See, little gears inside my head are starting to turn and I'm starting to understand this stuff.

But what I don't get....is what item would count as -1...


GetPlayerWeaponSlot returns an index to an entity. That entity is the weapon held by said client in said slot. If the client, for some reason, does not have a weapon in that slot, GetPlayerWeaponSlot will return -1.


Look at
SetGrenadeAmmo(client, ammo, index, slot) in your first post. Notice the use of IsValidEntity. You need to implement something similar in other parts of your code (e.g. the code we've been discussing).

thatdarnkid 01-15-2011 00:41

Re: Trying to fix these 2 persistent errors
 
Quote:

Originally Posted by Peace-Maker (Post 1393807)
If the player doesn't carry a primary/secondary or knife, it returns -1 for that weaponindex.

PHP Code:

GetUserFlagBits(client) && PREMIUMFLAG 

should be
PHP Code:

GetUserFlagBits(client) & PREMIUMFLAG 

it's the bitwise AND.

Alrighty. That's #1 on my list of things to do to the coding.


Quote:

Originally Posted by dirtyminuth (Post 1393808)

GetPlayerWeaponSlot returns an index to an entity. That entity is the weapon held by said client in said slot. If the client, for some reason, does not have a weapon in that slot, GetPlayerWeaponSlot will return -1.


Look at
SetGrenadeAmmo(client, ammo, index, slot) in your first post. Notice the use of IsValidEntity. You need to implement something similar in other parts of your code (e.g. the code we've been discussing).

Hmm....After reading this post a few times, the only thing my tired brain can pull out of it is "Change IsValidEntity to IsClientInGame in the SetGrenadeAmmo(client, ammo, index, slot)"

Not sure if that was the implication =\ But I'll pick up wherever this leaves off tomorrow. I'm in need of alot of sleep.

dirtyminuth 01-15-2011 00:46

Re: Trying to fix these 2 persistent errors
 
Quote:

Originally Posted by thatdarnkid (Post 1393869)
Hmm....After reading this post a few times, the only thing my tired brain can pull out of it is "Change IsValidEntity to IsClientInGame in the SetGrenadeAmmo(client, ammo, index, slot)"

Not sure if that was the implication =\ But I'll pick up wherever this leaves off tomorrow. I'm in need of alot of sleep.

No. SetGrenadeAmmo is correct. The single line of code I initially quoted is wrong. You need to add an IsValidEntity check to the return value of GetPlayerWeaponSlot in this line.

Man, helping some people is like herding cats.

thatdarnkid 01-15-2011 01:54

Re: Trying to fix these 2 persistent errors
 
Quote:

Originally Posted by dirtyminuth (Post 1393872)
No. SetGrenadeAmmo is correct. The single line of code I initially quoted is wrong. You need to add an IsValidEntity check to the return value of GetPlayerWeaponSlot in this line.

Man, helping some people is like herding cats.

Lol :P

Gimme a break. I'm tired, I should be asleep right now, but I'm not. Plus, keep in mind, I've never done this coding before. I'm basically just going through the code, reading everything and seeing what my brain can translate for me.

Ok, after reading....and re-reading...and re-re-reading all your posts, my brain finally decided to stop being stupid and I know the line you're talking about:
PHP Code:

SetEntProp(GetPlayerWeaponSlot(client0), Prop_Send"m_iClip1"GetEntProp(GetPlayerWeaponSlot(client0), Prop_Send"m_iClip1") + cClip); 

^-That much is clear to me. Now to rack my brains trying to figure out where to toss in the IsValidEntity()....


All times are GMT -4. The time now is 20:40.

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