AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Removing Weapons by Entity (https://forums.alliedmods.net/showthread.php?t=10214)

knekter 02-11-2005 21:07

Removing Weapons by Entity
 
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

XxAvalanchexX 02-11-2005 22:49

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.

knekter 02-11-2005 22:52

lol
 
Well I feel stupid, sorry for this pointless error :(

Da Bishop 02-12-2005 00:59

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 :D....



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)

XxAvalanchexX 02-12-2005 03:31

That's good if you only want to find one. And if weaponboxes had models.

Da Bishop 02-12-2005 10:23

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)


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

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