Raised This Month: $ Target: $400
 0% 

WeapPickup event crashes server


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shino
Senior Member
Join Date: May 2006
Old 06-02-2006 , 10:57   WeapPickup event crashes server
Reply With Quote #1

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
shino is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 06-02-2006 , 11:44  
Reply With Quote #2

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.
VEN is offline
shino
Senior Member
Join Date: May 2006
Old 06-03-2006 , 13:46  
Reply With Quote #3

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?
shino is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 06-03-2006 , 14:13  
Reply With Quote #4

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).
VEN is offline
shino
Senior Member
Join Date: May 2006
Old 06-03-2006 , 14:30  
Reply With Quote #5

thanks a lot!
shino is offline
Reply


Thread Tools
Display Modes

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 16:19.


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