]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/vehicles/sv_vehicles.qc
Introduce touch accessors
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / sv_vehicles.qc
index 7e5bc93eb87abfdf7bff47b8404dd652cee62338..bfb735197069f74cd86834a98f0c9a14c3dfb340 100644 (file)
@@ -208,7 +208,7 @@ void vehicles_projectile_damage(entity this, entity inflictor, entity attacker,
        {
                this.takedamage = DAMAGE_NO;
                this.event_damage = func_null;
-               this.think = this.use;
+               this.think = adaptor_think2use;
                this.nextthink = time;
        }
 }
@@ -232,6 +232,11 @@ void vehicles_projectile_explode()
        remove (self);
 }
 
+void vehicles_projectile_explode_use(entity this, entity actor, entity trigger)
+{
+       WITHSELF(this, vehicles_projectile_explode());
+}
+
 entity vehicles_projectile(entity this, string _mzlfx, Sound _mzlsound,
                                                   vector _org, vector _vel,
                                                   float _dmg, float _radi, float _force,  float _size,
@@ -256,8 +261,8 @@ entity vehicles_projectile(entity this, string _mzlfx, Sound _mzlsound,
        proj.bot_dodge          = true;
        proj.bot_dodgerating  = _dmg;
        proj.velocity            = _vel;
-       proj.touch                      = vehicles_projectile_explode;
-       proj.use                          = vehicles_projectile_explode;
+       settouch(proj, vehicles_projectile_explode);
+       proj.use                          = vehicles_projectile_explode_use;
        proj.owner                      = this;
        proj.realowner          = _owner;
        proj.think                      = SUB_Remove_self;
@@ -302,11 +307,11 @@ void vehicles_gib_think()
                self.nextthink = time + 0.1;
 }
 
-entity vehicle_tossgib(entity _template, vector _vel, string _tag, bool _burn, bool _explode, float _maxtime, vector _rot)
-{SELFPARAM();
+entity vehicle_tossgib(entity this, entity _template, vector _vel, string _tag, bool _burn, bool _explode, float _maxtime, vector _rot)
+{
        entity _gib = spawn();
        _setmodel(_gib, _template.model);
-       vector org = gettaginfo(self, gettagindex(self, _tag));
+       vector org = gettaginfo(this, gettagindex(this, _tag));
        setorigin(_gib, org);
        _gib.velocity = _vel;
        _gib.movetype = MOVETYPE_TOSS;
@@ -322,7 +327,7 @@ entity vehicle_tossgib(entity _template, vector _vel, string _tag, bool _burn, b
        {
                _gib.think = vehicles_gib_explode;
                _gib.nextthink = time + random() * _explode;
-               _gib.touch = vehicles_gib_explode;
+               settouch(_gib, vehicles_gib_explode);
        }
        else
        {
@@ -337,9 +342,9 @@ entity vehicle_tossgib(entity _template, vector _vel, string _tag, bool _burn, b
 bool vehicle_addplayerslot(    entity _owner,
                                                                entity _slot,
                                                                int _hud,
-                                                               string _hud_model,
+                                                               Model _hud_model,
                                                                bool(entity) _framefunc,
-                                                               void(bool) _exitfunc, float() _enterfunc)
+                                                               void(bool) _exitfunc, float(entity, entity) _enterfunc)
 {
        if(!(_owner.vehicle_flags & VHF_MULTISLOT))
                _owner.vehicle_flags |= VHF_MULTISLOT;
@@ -354,7 +359,7 @@ bool vehicle_addplayerslot( entity _owner,
        _slot.vehicle_hudmodel.viewmodelforclient = _slot;
        _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
 
-       _setmodel(_slot.vehicle_hudmodel, _hud_model);
+       setmodel(_slot.vehicle_hudmodel, _hud_model);
        setmodel(_slot.vehicle_viewport, MDL_Null);
 
        setattachment(_slot.vehicle_hudmodel, _slot, "");
@@ -381,62 +386,52 @@ vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string
        return vtag;
 }
 
-void vehicles_reset_colors()
-{SELFPARAM();
-       entity e;
-       float _effects = 0, _colormap;
-       vector _glowmod, _colormod;
-
+void vehicles_reset_colors(entity this)
+{
+       int eff = 0, cmap;
+       const vector cmod = '0 0 0';
+       if(this.team && teamplay)
+               cmap = 1024 + (this.team - 1) * 17;
+       else
+               cmap = 1024;
        if(autocvar_g_nodepthtestplayers)
-               _effects |= EF_NODEPTHTEST;
-
+               eff |= EF_NODEPTHTEST;
        if(autocvar_g_fullbrightplayers)
-               _effects |= EF_FULLBRIGHT;
-
-       if(self.team)
-               _colormap = 1024 + (self.team - 1) * 17;
-       else
-               _colormap = 1024;
-
-       _glowmod  = '0 0 0';
-       _colormod = '0 0 0';
+               eff |= EF_FULLBRIGHT;
 
        // Find all ents attacked to main model and setup effects, colormod etc.
-       e = findchainentity(tag_entity, self);
-       while(e)
+       FOREACH_ENTITY_ENT(tag_entity, this,
        {
-               if(e != self.vehicle_shieldent)
+               if(it != this.vehicle_shieldent)
                {
-                       e.effects   = _effects; //  | EF_LOWPRECISION;
-                       e.colormod  = _colormod;
-                       e.colormap  = _colormap;
-                       e.alpha  = 1;
+                       it.effects = eff;
+                       it.colormod = cmod;
+                       it.colormap = cmap;
+                       it.alpha = 1;
                }
-               e = e.chain;
-       }
+       });
+
        // Also check head tags
-       e = findchainentity(tag_entity, self.tur_head);
-       while(e)
+       FOREACH_ENTITY_ENT(tag_entity, this.tur_head,
        {
-               if(e != self.vehicle_shieldent)
+               if(it != this.vehicle_shieldent)
                {
-                       e.effects   = _effects; //  | EF_LOWPRECISION;
-                       e.colormod  = _colormod;
-                       e.colormap  = _colormap;
-                       e.alpha  = 1;
+                       it.effects = eff;
+                       it.colormod = cmod;
+                       it.colormap = cmap;
+                       it.alpha = 1;
                }
-               e = e.chain;
-       }
+       });
 
-       self.vehicle_hudmodel.effects  = self.effects  = _effects; // | EF_LOWPRECISION;
-       self.vehicle_hudmodel.colormod = self.colormod = _colormod;
-       self.vehicle_hudmodel.colormap = self.colormap = _colormap;
-       self.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
+       this.vehicle_hudmodel.effects  = this.effects  = eff; // | EF_LOWPRECISION;
+       this.vehicle_hudmodel.colormod = this.colormod = cmod;
+       this.vehicle_hudmodel.colormap = this.colormap = cmap;
+       this.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
 
-       self.alpha       = 1;
-       self.avelocity = '0 0 0';
-       self.velocity  = '0 0 0';
-       self.effects   = _effects;
+       this.alpha       = 1;
+       this.avelocity = '0 0 0';
+       this.velocity  = '0 0 0';
+       this.effects   = eff;
 }
 
 void vehicles_clearreturn(entity veh)
@@ -483,46 +478,43 @@ void vehicles_showwp_goaway()
 
 void vehicles_showwp()
 {SELFPARAM();
-       entity oldself = world;
        vector rgb;
 
-       if(self.cnt)
+       entity ent = this;
+
+       if(ent.cnt)
        {
-               self.think        = vehicles_return;
-               self.nextthink  = self.cnt;
+               ent.think = vehicles_return;
+               ent.nextthink = ent.cnt;
        }
        else
        {
-               self.think        = vehicles_return;
-               self.nextthink  = time +1;
-
-               oldself = self;
-               setself(spawn());
-               setmodel(self, MDL_Null);
-               self.team = oldself.wp00.team;
-               self.wp00 = oldself.wp00;
-               setorigin(self, oldself.wp00.pos1);
-
-               self.nextthink = time + 5;
-               self.think = vehicles_showwp_goaway;
+               ent.think         = vehicles_return;
+               ent.nextthink  = time + 1;
+
+               ent = spawn();
+               setmodel(ent, MDL_Null);
+               ent.team = this.wp00.team;
+               ent.wp00 = this.wp00;
+               setorigin(ent, this.wp00.pos1);
+
+               ent.nextthink = time + 5;
+               ent.think = vehicles_showwp_goaway;
        }
 
-       if(teamplay && self.team)
-               rgb = Team_ColorRGB(self.team);
+       if(teamplay && ent.team)
+               rgb = Team_ColorRGB(ent.team);
        else
                rgb = '1 1 1';
-       entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Vehicle);
+       entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, ent, '0 0 64', world, 0, ent, waypointsprite_attached, true, RADARICON_Vehicle);
        wp.colormod = rgb;
-       if(self.waypointsprite_attached)
+       if(ent.waypointsprite_attached)
        {
-               WaypointSprite_UpdateRule(self.waypointsprite_attached, self.wp00.team, SPRITERULE_DEFAULT);
+               WaypointSprite_UpdateRule(ent.waypointsprite_attached, ent.wp00.team, SPRITERULE_DEFAULT);
                if(this == NULL)
-                       WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, self.nextthink);
-               WaypointSprite_Ping(self.waypointsprite_attached);
+                       WaypointSprite_UpdateBuildFinished(ent.waypointsprite_attached, ent.nextthink);
+               WaypointSprite_Ping(ent.waypointsprite_attached);
        }
-
-       if(this)
-               setself(this);
 }
 
 void vehicles_setreturn(entity veh)
@@ -551,29 +543,29 @@ void vehicles_setreturn(entity veh)
 
 }
 
-void vehicle_use()
-{SELFPARAM();
-       LOG_TRACE("vehicle ",self.netname, " used by ", activator.classname, "\n");
+void vehicle_use(entity this, entity actor, entity trigger)
+{
+       LOG_TRACE("vehicle ",this.netname, " used by ", actor.classname, "\n");
 
-       self.tur_head.team = activator.team;
+       this.tur_head.team = actor.team;
 
-       if(self.tur_head.team == 0)
-               self.active = ACTIVE_NOT;
+       if(this.tur_head.team == 0)
+               this.active = ACTIVE_NOT;
        else
-               self.active = ACTIVE_ACTIVE;
+               this.active = ACTIVE_ACTIVE;
 
-       if(self.active == ACTIVE_ACTIVE && !IS_DEAD(self) && !gameover)
+       if(this.active == ACTIVE_ACTIVE && !IS_DEAD(this) && !gameover)
        {
-               LOG_TRACE("Respawning vehicle: ", self.netname, "\n");
-               if(self.effects & EF_NODRAW)
+               LOG_TRACE("Respawning vehicle: ", this.netname, "\n");
+               if(this.effects & EF_NODRAW)
                {
-                       self.think = vehicles_spawn;
-                       self.nextthink = time + 3;
+                       this.think = vehicles_spawn;
+                       this.nextthink = time + 3;
                }
                else
                {
-                       vehicles_setreturn(self);
-                       vehicles_reset_colors();
+                       vehicles_setreturn(this);
+                       vehicles_reset_colors(this);
                }
        }
 }
@@ -716,9 +708,9 @@ void vehicles_damage(entity this, entity inflictor, entity attacker, float damag
        {
                if(this.owner)
                        if(this.vehicle_flags & VHF_DEATHEJECT)
-                               WITH(entity, self, this, vehicles_exit(VHEF_EJECT));
+                               WITHSELF(this, vehicles_exit(VHEF_EJECT));
                        else
-                               WITH(entity, self, this, vehicles_exit(VHEF_RELEASE));
+                               WITHSELF(this, vehicles_exit(VHEF_RELEASE));
 
 
                antilag_clear(this, this);
@@ -740,21 +732,21 @@ float vehicles_crushable(entity e)
        return false;
 }
 
-void vehicles_impact(float _minspeed, float _speedfac, float _maxpain)
-{SELFPARAM();
+void vehicles_impact(entity this, float _minspeed, float _speedfac, float _maxpain)
+{
        if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
                return;
 
-       if(self.play_time < time)
+       if(this.play_time < time)
        {
-               float wc = vlen(self.velocity - self.oldvelocity);
-               //dprint("oldvel: ", vtos(self.oldvelocity), "\n");
-               //dprint("vel: ", vtos(self.velocity), "\n");
+               float wc = vlen(this.velocity - this.oldvelocity);
+               //dprint("oldvel: ", vtos(this.oldvelocity), "\n");
+               //dprint("vel: ", vtos(this.velocity), "\n");
                if(_minspeed < wc)
                {
                        float take = min(_speedfac * wc, _maxpain);
-                       Damage (self, world, world, take, DEATH_FALL.m_id, self.origin, '0 0 0');
-                       self.play_time = time + 0.25;
+                       Damage (this, world, world, take, DEATH_FALL.m_id, this.origin, '0 0 0');
+                       this.play_time = time + 0.25;
 
                        //dprint("wc: ", ftos(wc), "\n");
                        //dprint("take: ", ftos(take), "\n");
@@ -830,7 +822,6 @@ void vehicles_exit(bool eject)
                if (_vehicle.vehicle_flags & VHF_PLAYERSLOT)
                {
                        _vehicle.vehicle_exit(eject);
-                       setself(this);
                        vehicles_exit_running = false;
                        return;
                }
@@ -901,7 +892,7 @@ void vehicles_exit(bool eject)
        _vehicle.vehicle_exit(eject);
 
        vehicles_setreturn(_vehicle);
-       vehicles_reset_colors();
+       vehicles_reset_colors(_vehicle);
        _vehicle.owner = world;
 
        CSQCMODEL_AUTOINIT(self);
@@ -962,7 +953,7 @@ bool vehicle_impulse(entity this, int imp)
 }
 
 void vehicles_enter(entity pl, entity veh)
-{SELFPARAM();
+{
    // Remove this when bots know how to use vehicles
        if((IS_BOT_CLIENT(pl) && !autocvar_g_vehicles_allow_bots))
                return;
@@ -979,28 +970,17 @@ void vehicles_enter(entity pl, entity veh)
        if(veh.vehicle_flags & VHF_MULTISLOT)
        if(veh.owner)
        {
-               setself(veh);
-               other = pl; // TODO: fix
-
                if(!veh.gunner1)
                if(time >= veh.gun1.phase)
                if(veh.gun1.vehicle_enter)
-               if(veh.gun1.vehicle_enter())
-               {
-                       setself(this);
+               if(veh.gun1.vehicle_enter(veh, pl))
                        return;
-               }
 
                if(!veh.gunner2)
                if(time >= veh.gun2.phase)
                if(veh.gun2.vehicle_enter)
-               if(veh.gun2.vehicle_enter())
-               {
-                       setself(this);
+               if(veh.gun2.vehicle_enter(veh, pl))
                        return;
-               }
-
-               setself(this);
        }
 
        if(teamplay)
@@ -1102,11 +1082,9 @@ void vehicles_enter(entity pl, entity veh)
 
        MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
 
-       setself(veh);
        CSQCModel_UnlinkEntity(veh);
        Vehicle info = Vehicles_from(veh.vehicleid);
-       info.vr_enter(info, veh);
-       setself(this);
+       WITHSELF(veh, info.vr_enter(info, veh));
 
        antilag_clear(pl, CS(pl));
 }
@@ -1135,7 +1113,7 @@ void vehicles_spawn()
        self.vehicle_hudmodel.viewmodelforclient = self;
 
        self.owner                              = world;
-       self.touch                              = vehicles_touch;
+       settouch(self, vehicles_touch);
        self.event_damage               = vehicles_damage;
        self.iscreature                 = true;
        self.teleportable               = false; // no teleporting for vehicles, too buggy
@@ -1167,7 +1145,7 @@ void vehicles_spawn()
 
        FOREACH_CLIENT(IS_PLAYER(it) && it.hook.aiment == self, RemoveGrapplingHook(it));
 
-       vehicles_reset_colors();
+       vehicles_reset_colors(self);
 
        Vehicle info = Vehicles_from(self.vehicleid);
        info.vr_spawn(info, self);
@@ -1175,121 +1153,118 @@ void vehicles_spawn()
        CSQCMODEL_AUTOINIT(self);
 }
 
-bool vehicle_initialize(entity veh, bool nodrop)
-{SELFPARAM();
+bool vehicle_initialize(entity this, Vehicle info, bool nodrop)
+{
        if(!autocvar_g_vehicles)
                return false;
 
-       if(!veh.vehicleid)
+       if(!info.vehicleid)
                return false;
 
-       if(!veh.tur_head) {
-               Vehicle info = Vehicles_from(veh.vehicleid);
+       if(!this.tur_head)
                info.vr_precache(info);
-       }
 
-       if(self.targetname && self.targetname != "")
+       if(this.targetname && this.targetname != "")
        {
-               self.vehicle_controller = find(world, target, self.targetname);
-               if(!self.vehicle_controller)
+               this.vehicle_controller = find(world, target, this.targetname);
+               if(!this.vehicle_controller)
                {
                        bprint("^1WARNING: ^7Vehicle with invalid .targetname\n");
-                       self.active = ACTIVE_ACTIVE;
+                       this.active = ACTIVE_ACTIVE;
                }
                else
                {
-                       self.team = self.vehicle_controller.team;
-                       self.use = vehicle_use;
+                       this.team = this.vehicle_controller.team;
+                       this.use = vehicle_use;
 
                        if(teamplay)
                        {
-                               if(self.vehicle_controller.team == 0)
-                                       self.active = ACTIVE_NOT;
+                               if(this.vehicle_controller.team == 0)
+                                       this.active = ACTIVE_NOT;
                                else
-                                       self.active = ACTIVE_ACTIVE;
+                                       this.active = ACTIVE_ACTIVE;
                        }
                }
        }
-       else { self.active = ACTIVE_ACTIVE; }
+       else { this.active = ACTIVE_ACTIVE; }
 
-       if(self.team && (!teamplay || !autocvar_g_vehicles_teams))
-               self.team = 0;
+       if(this.team && (!teamplay || !autocvar_g_vehicles_teams))
+               this.team = 0;
 
-       if(self.mdl == "" || !self.mdl)
-               _setmodel(self, veh.model);
+       if(this.mdl == "" || !this.mdl)
+               _setmodel(this, info.model);
        else
-               _setmodel(self, self.mdl);
-
-       self.vehicle_flags |= VHF_ISVEHICLE;
-
-       self.vehicle_viewport           = new(vehicle_viewport);
-       self.vehicle_hudmodel           = new(vehicle_hudmodel);
-       self.tur_head                           = new(tur_head);
-       self.tur_head.owner                     = self;
-       self.takedamage                         = DAMAGE_NO;
-       self.bot_attack                         = true;
-       self.iscreature                         = true;
-       self.teleportable                       = false; // no teleporting for vehicles, too buggy
-       self.damagedbycontents          = true;
-       self.vehicleid                          = veh.vehicleid;
-       self.PlayerPhysplug                     = veh.PlayerPhysplug;
-       self.event_damage                       = func_null;
-       self.touch                                      = vehicles_touch;
-       self.think                                      = vehicles_spawn;
-       self.nextthink                          = time;
-       self.effects                            = EF_NODRAW;
-       self.dphitcontentsmask          = DPCONTENTS_BODY | DPCONTENTS_SOLID;
+               _setmodel(this, this.mdl);
+
+       this.vehicle_flags |= VHF_ISVEHICLE;
+
+       this.vehicle_viewport           = new(vehicle_viewport);
+       this.vehicle_hudmodel           = new(vehicle_hudmodel);
+       this.tur_head                           = new(tur_head);
+       this.tur_head.owner                     = this;
+       this.takedamage                         = DAMAGE_NO;
+       this.bot_attack                         = true;
+       this.iscreature                         = true;
+       this.teleportable                       = false; // no teleporting for vehicles, too buggy
+       this.damagedbycontents          = true;
+       this.vehicleid                          = info.vehicleid;
+       this.PlayerPhysplug                     = info.PlayerPhysplug;
+       this.event_damage                       = func_null;
+       settouch(this, vehicles_touch);
+       this.think                                      = vehicles_spawn;
+       this.nextthink                          = time;
+       this.effects                            = EF_NODRAW;
+       this.dphitcontentsmask          = DPCONTENTS_BODY | DPCONTENTS_SOLID;
 
        if(autocvar_g_playerclip_collisions)
-               self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
+               this.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
 
        if(autocvar_g_nodepthtestplayers)
-               self.effects |= EF_NODEPTHTEST;
+               this.effects |= EF_NODEPTHTEST;
 
        if(autocvar_g_fullbrightplayers)
-               self.effects |= EF_FULLBRIGHT;
+               this.effects |= EF_FULLBRIGHT;
 
-       _setmodel(self.vehicle_hudmodel, veh.hud_model);
-       setmodel(self.vehicle_viewport, MDL_Null);
+       _setmodel(this.vehicle_hudmodel, info.hud_model);
+       setmodel(this.vehicle_viewport, MDL_Null);
 
-       if(veh.head_model != "")
+       if(info.head_model != "")
        {
-               _setmodel(self.tur_head, veh.head_model);
-               setattachment(self.tur_head, self, veh.tag_head);
-               setattachment(self.vehicle_hudmodel, self.tur_head, veh.tag_hud);
-               setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
+               _setmodel(this.tur_head, info.head_model);
+               setattachment(this.tur_head, this, info.tag_head);
+               setattachment(this.vehicle_hudmodel, this.tur_head, info.tag_hud);
+               setattachment(this.vehicle_viewport, this.vehicle_hudmodel, info.tag_view);
        }
        else
        {
-               setattachment(self.tur_head, self, "");
-               setattachment(self.vehicle_hudmodel, self, veh.tag_hud);
-               setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
+               setattachment(this.tur_head, this, "");
+               setattachment(this.vehicle_hudmodel, this, info.tag_hud);
+               setattachment(this.vehicle_viewport, this.vehicle_hudmodel, info.tag_view);
        }
 
-       setsize(self, veh.mins, veh.maxs);
+       setsize(this, info.mins, info.maxs);
 
        if(!nodrop)
        {
-               setorigin(self, self.origin);
-               tracebox(self.origin + '0 0 100', veh.mins, veh.maxs, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
-               setorigin(self, trace_endpos);
+               setorigin(this, this.origin);
+               tracebox(this.origin + '0 0 100', info.mins, info.maxs, this.origin - '0 0 10000', MOVE_WORLDONLY, this);
+               setorigin(this, trace_endpos);
        }
 
-       self.pos1 = self.origin;
-       self.pos2 = self.angles;
-       self.tur_head.team = self.team;
+       this.pos1 = this.origin;
+       this.pos2 = this.angles;
+       this.tur_head.team = this.team;
 
-       Vehicle info = Vehicles_from(veh.vehicleid);
-       info.vr_setup(info, veh);
+       info.vr_setup(info, this);
 
-       if(self.active == ACTIVE_NOT)
-               self.nextthink = 0; // wait until activated
+       if(this.active == ACTIVE_NOT)
+               this.nextthink = 0; // wait until activated
        else if(autocvar_g_vehicles_delayspawn)
-               self.nextthink = time + self.respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
+               this.nextthink = time + this.respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
        else
-               self.nextthink = time + game_starttime;
+               this.nextthink = time + game_starttime;
 
-       if(MUTATOR_CALLHOOK(VehicleSpawn))
+       if(MUTATOR_CALLHOOK(VehicleSpawn, this))
                return false;
 
        return true;