5 #include <lib/warpzone/util_server.qh>
6 #include <common/weapons/_all.qh>
7 #include <server/defs.qh>
8 #include <common/deathtypes/all.qh>
13 * Adds spawnfunc_trigger_swamp and suppoart routines for xonotic 1.2.1+
14 * Author tZork (Jakob MG)
19 .float swamp_interval; //Hurt players in swamp with this interval
20 .float swamp_slowdown; //Players in swamp get slowd down by this mutch 0-1 is slowdown 1-~ is speedup (!?)
21 .float swamp_lifetime; // holds the points remaining until slug dies (not quite health!)
25 spawnfunc(trigger_swamp);
27 void swamp_touch(entity this, entity toucher);
28 void swampslug_think(entity this);
32 * Uses a entity calld swampslug to handle players in the swamp
33 * It works like this: When the plyer enters teh swamp the spawnfunc_trigger_swamp
34 * attaches a new "swampslug" to the player. As long as the plyer is inside
35 * the swamp the swamp gives the slug new health. But the slug slowly kills itself
36 * so when the player goes outside the swamp, it dies and releases the player from the
37 * swamps curses (dmg/slowdown)
39 * I do it this way becuz there is no "untouch" event.
41 void swampslug_think(entity this)
43 //Slowly kill the slug
44 this.swamp_lifetime -= 1;
46 //Slug dead? then remove curses.
47 if(GetResource(this, RES_HEALTH) <= 0)
49 this.owner.in_swamp = 0;
51 //centerprint(this.owner,"Killing slug...\n");
55 // Slug still alive, so we are still in the swamp
56 // Or we have exited it very recently.
57 // Do the damage and renew the timer.
59 Damage (this.owner, this, this, this.dmg, DEATH_SWAMP.m_id, DMG_NOWEP, this.owner.origin, '0 0 0');
62 this.nextthink = time + this.swamp_interval;
65 void swamp_touch(entity this, entity toucher)
67 // If whatever thats touching the swamp is not a player
68 // or if its a dead player, just dont care abt it.
69 if(!IS_PLAYER(toucher) || IS_DEAD(toucher))
72 EXACTTRIGGER_TOUCH(this, toucher);
74 // Chech if player alredy got a swampslug.
75 if(toucher.in_swamp != 1)
78 //centerprint(toucher,"Entering swamp!\n");
79 toucher.swampslug = spawn();
80 toucher.swampslug.swamp_lifetime = 2;
81 setthink(toucher.swampslug, swampslug_think);
82 toucher.swampslug.nextthink = time;
83 toucher.swampslug.owner = toucher;
84 toucher.swampslug.dmg = this.dmg;
85 toucher.swampslug.swamp_interval = this.swamp_interval;
86 toucher.swamp_slowdown = this.swamp_slowdown;
91 //toucher.in_swamp = 1;
93 //Revitalize players swampslug
94 toucher.swampslug.swamp_lifetime = 2;
97 REGISTER_NET_LINKED(ENT_CLIENT_SWAMP)
100 float swamp_send(entity this, entity to, float sf)
102 WriteHeader(MSG_ENTITY, ENT_CLIENT_SWAMP);
104 WriteByte(MSG_ENTITY, this.dmg); // can probably get away with using a single byte here
105 WriteByte(MSG_ENTITY, this.swamp_slowdown);
106 WriteByte(MSG_ENTITY, this.swamp_interval);
108 trigger_common_write(this, false);
113 void swamp_link(entity this)
115 trigger_link(this, swamp_send);
118 /*QUAKED spawnfunc_trigger_swamp (.5 .5 .5) ?
119 Players gettin into the swamp will
120 get slowd down and damaged
122 spawnfunc(trigger_swamp)
126 settouch(this, swamp_touch);
128 // Setup default keys, if missing
131 if(this.swamp_interval <= 0)
132 this.swamp_interval = 1;
133 if(this.swamp_slowdown <= 0)
134 this.swamp_slowdown = 0.5;
141 NET_HANDLE(ENT_CLIENT_SWAMP, bool isnew)
143 this.dmg = ReadByte();
144 this.swamp_slowdown = ReadByte();
145 this.swamp_interval = ReadByte();
147 trigger_common_read(this, false);
151 this.classname = "trigger_swamp";
152 this.solid = SOLID_TRIGGER;
153 settouch(this, swamp_touch);
154 this.drawmask = MASK_NORMAL;
155 this.move_time = time;
156 this.entremove = trigger_remove_generic;