Raised This Month: $ Target: $400
 0% 

Removing Weapons by Entity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
knekter
Senior Member
Join Date: Mar 2004
Location: PA
Old 02-11-2005 , 21:07   Removing Weapons by Entity
Reply With Quote #1

Im trying to remove specific weapons that are dropped by players, but im having a hard time getting this to work. I get an error: "unknown entity 97", and I have no Idea whats wrong.... heres the code:

Code:
public handle_drop(id) {     if(!get_cvar_num(MOD))         return PLUGIN_HANDLED     new clip, ammo     new arsenal = get_user_weapon(id, clip, ammo)     if(arsenal == CSW_DEAGLE) {         new model[32]         new tEnt, oId, wEnt         tEnt = find_ent_by_class(-1, "weaponbox")         while(tEnt > 0) {             entity_get_string(tEnt, EV_SZ_model, model, 31)             if(equali(model, "models/w_deagle.mdl")) {                 oId = entity_get_edict(tEnt, EV_ENT_owner)                 if(oId > 0 && oId < 33) {                     remove_entity(tEnt)                     wEnt = find_ent_by_class(-1, "weapon_deagle")                     while(wEnt > -1) {                         oId = entity_get_edict(wEnt, EV_ENT_owner)                         if(oId == tEnt)                             remove_entity(wEnt)                     }                 }             }         }  return PLUGIN_CONTINUE }

I used register_clcmd("drop","handle_drop") to catch a players drop. I don't know why this won't work. The server just crashes when I execute my plugin.... Thanks for the help.

-Knekter
__________________
More updates for Matrix Mod!
knekter is offline
Send a message via AIM to knekter Send a message via MSN to knekter
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 02-11-2005 , 22:49  
Reply With Quote #2

Let's take a look at your code here:

Code:
        tEnt = find_ent_by_class(-1, "weaponbox")         while(tEnt > 0) {

Let's say it finds a weaponbox with an id of 37. tEnt is now 37. Now you're telling the plugin that as long as tEnt (37 in this case) is larger than 0 (which it is), then do what you tell it to. However, tEnt remains 37 forever and ever and ever so it keeps looping and causes an infinite loop, thus crashing it. The correct way for looping through all entities would be:

Code:
while((tEnt = find_ent_by_class(tEnt,"weaponbox")) != 0) {

This infinite loop error occurs twice in your code.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
knekter
Senior Member
Join Date: Mar 2004
Location: PA
Old 02-11-2005 , 22:52   lol
Reply With Quote #3

Well I feel stupid, sorry for this pointless error
__________________
More updates for Matrix Mod!
knekter is offline
Send a message via AIM to knekter Send a message via MSN to knekter
Da Bishop
Senior Member
Join Date: Aug 2004
Location: Chester County PA
Old 02-12-2005 , 00:59  
Reply With Quote #4

Okay you are going about this all wrong.. im gonna show you a code that works all the time and is perfect in all means ....



Code:
new Model[51] new Maxplayers = get_maxplayers() new gunbox = find_ent_by_class(Maxplayers + 1, "weaponbox") entity_get_string(gunbox, EV_SZ_model, Model, 50) if(equali(model, "models/w_deagle.mdl"))         call_think(gunbox)
__________________
Anything that is done can only be done better by urself - since life is a opinion make it the way urs feel its best

~live by it
Da Bishop is offline
Send a message via MSN to Da Bishop
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 02-12-2005 , 03:31  
Reply With Quote #5

That's good if you only want to find one. And if weaponboxes had models.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Da Bishop
Senior Member
Join Date: Aug 2004
Location: Chester County PA
Old 02-12-2005 , 10:23  
Reply With Quote #6

No, he is doing it through a drop command, and u can list several models for the check, also any weapon will have a model in the weaponbox so i don't konw what you are talking about..

Code:
new Model[51] new Maxplayers = get_maxplayers() new gunbox = find_ent_by_class(Maxplayers + 1, "weaponbox") entity_get_string(gunbox, EV_SZ_model, Model, 50) if(equali(model, "models/w_deagle.mdl")  || (model, "models/w_awp.mdl"))         call_think(gunbox)
__________________
Anything that is done can only be done better by urself - since life is a opinion make it the way urs feel its best

~live by it
Da Bishop is offline
Send a message via MSN to Da Bishop
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 14:31.


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