AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   WeapPickup event crashes server (https://forums.alliedmods.net/showthread.php?t=29270)

shino 06-02-2006 10:57

WeapPickup event crashes server
 
here's litte bit of code:
Code:
public plugin_init() {     register_event("WeapPickup","SetKnife","b") } public SetKnife(index) {     new players[32],num,i     get_players(players,num)     for(i = 0; i <= num; i++) {         new id = players[i]         if (is_user_alive(id) && cs_get_user_team(id) == CS_TEAM_T) {             strip_user_weapons(id)             give_item(id,"weapon_knife")         }     } }

few seconds after freeze time expires, server crashes with ED:Alloc: no free edicts. i would be pleased if someone could help me :)

VEN 06-02-2006 11:44

On weapon collect you give a knife that action triggers WeapPickup event which hooked to the SetKnife function which strips weapons and give knife again. Your plugin is an infinite loop.

shino 06-03-2006 13:46

so, if i remove the "give_item(id,"weapon_knife")", the problems should stop? i'm confused, because if i do that, server still crashes. how exactly should i repair the code then?

VEN 06-03-2006 14:13

This should work:
Code:
#include <amxmodx> #include <fun> public plugin_init() {     register_event("WeapPickup", "event_weap_pickup", "be", "1!29") } public event_weap_pickup(id) {     set_task(0.1, "task_strip_and_give", id) } public task_strip_and_give(id) {     if (is_user_alive(id) && get_user_team(id) == 1) {         strip_user_weapons(id)         give_item(id, "weapon_knife")     } }
Condition "1!29" means that we skip knife pickup (knife ID is 29).
And set_task(0.1 ... means that we use 0.1 sec delay, because player still don't have a weapon (only event is triggered).

shino 06-03-2006 14:30

thanks a lot!


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

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