AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   find_ent_by_class problems (https://forums.alliedmods.net/showthread.php?t=28778)

shino 05-22-2006 11:16

find_ent_by_class problems
 
here's my little issue:

Code:
public WeaponDrop(id) {     engclient_cmd(id,"drop","weapon_usp")     set_task(0.1,"DeleteUSP") } public DeleteUSP() {     new USP,szModel[33]     while ((USP = find_ent_by_class(-1, "weapon_usp")) != 0)     {         entity_get_string(USP, EV_SZ_model, szModel, 32)         if (equali(szModel, "models/w_usp.mdl"))         {             remove_entity(USP)             return PLUGIN_CONTINUE         }     }         return PLUGIN_CONTINUE }

as soon usp is dropped, the remove task performs and the server crashes. any suggestions? :?

VEN 05-22-2006 12:03

Yes. I don't recommend "coding" such thing - it's not that simple as MOST of the coders think. Just use fm_strip_user_gun from the Fakemeta Utilities or search for my strip_user_gun function.

shino 05-22-2006 14:35

how should i then use this function, like this?
Code:
public WeaponDrop(id) {     fm_strip_user_gun(CSW_USP) } thanks!  :)

VEN 05-22-2006 14:38

You should specify the player's index:
Code:
fm_strip_user_gun(id, CSW_USP)

Orangutanz 05-22-2006 19:18

Code:
public DeleteUSP() {     new USP = find_ent_by_class(-1, "weapon_usp")     while(USP)     {         remove_entity(USP)         USP = find_ent_by_class(USP, "weapon_usp")     } }
However its best to use what VEN recommended! The above is only a portion of what you must code to remove weapons.

shino 05-23-2006 14:09

so, used fm_strip_user_gun as you said:
Code:
public WeaponDrop(players[]) {     new players[32],num,i     get_players(players,num)     for(i = 0; i <= num; i++) {         new id = players[i]         if (is_user_bot(id) && is_user_alive(id)) {             fm_strip_user_gun(id,CSW_AK47)             fm_strip_user_gun(id,CSW_AUG)             fm_strip_user_gun(id,CSW_AWP)             fm_strip_user_gun(id,CSW_C4)             fm_strip_user_gun(id,CSW_DEAGLE)             fm_strip_user_gun(id,CSW_ELITE)             fm_strip_user_gun(id,CSW_FAMAS)             fm_strip_user_gun(id,CSW_FIVESEVEN)             fm_strip_user_gun(id,CSW_FLASHBANG)             fm_strip_user_gun(id,CSW_G3SG1)             fm_strip_user_gun(id,CSW_GALI)             fm_strip_user_gun(id,CSW_GALIL)             fm_strip_user_gun(id,CSW_GLOCK18)             fm_strip_user_gun(id,CSW_HEGRENADE)             fm_strip_user_gun(id,CSW_M249)             fm_strip_user_gun(id,CSW_M3)             fm_strip_user_gun(id,CSW_M4A1)             fm_strip_user_gun(id,CSW_MAC10)             fm_strip_user_gun(id,CSW_MP5NAVY)             fm_strip_user_gun(id,CSW_P228)             fm_strip_user_gun(id,CSW_P90)             fm_strip_user_gun(id,CSW_SCOUT)             fm_strip_user_gun(id,CSW_SG550)             fm_strip_user_gun(id,CSW_SG552)             fm_strip_user_gun(id,CSW_SMOKEGRENADE)             fm_strip_user_gun(id,CSW_TMP)             fm_strip_user_gun(id,CSW_UMP45)             fm_strip_user_gun(id,CSW_USP)             fm_strip_user_gun(id,CSW_VEST)             fm_strip_user_gun(id,CSW_VESTHELM)             fm_strip_user_gun(id,CSW_XM1014)         }     }     return PLUGIN_CONTINUE }

but this is only performed on one bot. why?

Xanimos 05-23-2006 14:36

with get players you can get just alive bots with
Code:
new Players[32] , pnum get_players(Players , pnum , "ad")
So you don't need to check if they are alive or if they are bots.

Also you don't do <= pnum is < pnum

And don't use new id = ... inside of a loop its horrible practice. Causes more load.

VEN 05-24-2006 02:43

You can't strip vest(helm) and grenades with that function, it's for guns.
If you want to strip everything except knife why don't you use strip_user_weapons and then give_item knife?


All times are GMT -4. The time now is 16:31.

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