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 support routines for nexuiz 1.2.1+ and xonotic
14 * Author tZork (Jakob MG)
21 * Uses a entity calld swampslug to handle players in the swamp
22 * It works like this: When the plyer enters teh swamp the spawnfunc_trigger_swamp
23 * attaches a new "swampslug" to the player. As long as the plyer is inside
24 * the swamp the swamp gives the slug new health. But the slug slowly kills itself
25 * so when the player goes outside the swamp, it dies and releases the player from the
26 * swamps curses (dmg/slowdown)
28 * I do it this way becuz there is no "untouch" event.
30 void swampslug_think(entity this)
32 //Slowly kill the slug
33 this.swamp_lifetime -= 1;
35 //Slug dead? then remove curses.
36 if(GetResource(this, RES_HEALTH) <= 0)
38 if(this.owner.swampslug == this)
40 this.owner.in_swamp = false;
41 this.owner.swampslug = NULL;
44 //centerprint(this.owner,"Killing slug...\n");
48 // Slug still alive, so we are still in the swamp
49 // Or we have exited it very recently.
50 // Do the damage and renew the timer.
52 Damage (this.owner, this, this, this.dmg, DEATH_SWAMP.m_id, DMG_NOWEP, this.owner.origin, '0 0 0');
55 this.nextthink = time + this.swamp_interval;
58 void swamp_touch(entity this, entity toucher)
60 // If whatever thats touching the swamp is not a player
61 // or if its a dead player, just dont care abt it.
62 if(!IS_PLAYER(toucher) || IS_DEAD(toucher))
65 EXACTTRIGGER_TOUCH(this, toucher);
67 // Chech if player alredy got a swampslug.
71 //centerprint(toucher,"Entering swamp!\n");
72 if(!toucher.swampslug) // just incase
73 toucher.swampslug = spawn();
74 toucher.swampslug.swamp_lifetime = 2;
75 setthink(toucher.swampslug, swampslug_think);
76 toucher.swampslug.nextthink = time;
77 toucher.swampslug.owner = toucher;
78 toucher.swampslug.dmg = this.dmg;
79 toucher.swampslug.swamp_interval = this.swamp_interval;
80 toucher.swamp_slowdown = this.swamp_slowdown;
81 toucher.in_swamp = true;
85 //toucher.in_swamp = true;
87 //Revitalize players swampslug
88 toucher.swampslug.swamp_lifetime = 2;
91 REGISTER_NET_LINKED(ENT_CLIENT_SWAMP)
94 float swamp_send(entity this, entity to, float sf)
96 WriteHeader(MSG_ENTITY, ENT_CLIENT_SWAMP);
98 WriteByte(MSG_ENTITY, this.dmg); // can probably get away with using a single byte here
99 WriteByte(MSG_ENTITY, this.swamp_slowdown);
100 WriteByte(MSG_ENTITY, this.swamp_interval);
102 trigger_common_write(this, false);
107 void swamp_link(entity this)
109 trigger_link(this, swamp_send);
112 /*QUAKED spawnfunc_trigger_swamp (.5 .5 .5) ?
113 Players in the swamp will be
114 slowed down and damaged over time
116 spawnfunc(trigger_swamp)
120 settouch(this, swamp_touch);
122 // Setup default keys, if missing
125 if(this.swamp_interval <= 0)
126 this.swamp_interval = 1;
127 if(this.swamp_slowdown <= 0)
128 this.swamp_slowdown = 0.5;
135 NET_HANDLE(ENT_CLIENT_SWAMP, bool isnew)
137 this.dmg = ReadByte();
138 this.swamp_slowdown = ReadByte();
139 this.swamp_interval = ReadByte();
141 trigger_common_read(this, false);
145 this.classname = "trigger_swamp";
146 this.solid = SOLID_TRIGGER;
147 settouch(this, swamp_touch);
148 this.drawmask = MASK_NORMAL;
149 this.move_time = time;
150 this.entremove = trigger_remove_generic;