A simple task, I thought. Below cog is a class cog for a vase/pot template. It is producing a shatter effect and creates a random powerup when damaged enough. The vase then respawns after a set time.
Now, that works just fine, but the template is a _throwable one, so you can move the vases around. It would now be nice when they could be "respawned" at their original locations, instead of the current ones...
I've tried it with simple variables and heaps, but both seem to be overridden by the next vase's class cog...
Now, that works just fine, but the template is a _throwable one, so you can move the vases around. It would now be nice when they could be "respawned" at their original locations, instead of the current ones...
Code:
# Jedi Knight Cog Script # # ACTOR_POT.COG # # This cog makes a pot explode if damaged enough # Possibly creates a powerup # Actually a class COG # # 2005 Jedi I # modified by zagibu@gmx.ch # ======================================================================================== symbols thing victim local template exp_tpl=+crate_exp local template powerup0=+dhealthpack local template powerup1=+dbactatank local template powerup2=+dshield local template powerup3=+dbattery local template powerup4=+denergycell local template powerup5=+dpowercell local template powerup6=+dsmbp local sound respawn_snd=Activate01.wav local flex life=40 local flex wait_time=30 local flex health local flex damage local flex rval local flex geo_mode local flex collide_type local message created message damaged message timer end # ======================================================================================== code created: // Give the victim it's initial health SetThingUserData(GetSenderRef(), life); Return; # ........................................................................................ damaged: victim = GetSenderRef(); health = GetThingUserData(victim); damage = GetParam(0); // Check type of damage and handle impact damage as a special case if(GetParam(1) & 0x1) { // Check if a player has applied impact damage to the victim if(GetThingType(GetThingParent(GetSourceRef())) == 10) Return; } // Are we applying enough damage to "kill" the poor thing if(damage >= health) { // Create the explosion template at the damaged thing's position CreateThing(exp_tpl, victim); // Remove the victim (render it invisible and disable it's collision switch) geo_mode = GetThingCurGeoMode(victim); SetThingCurGeoMode(victim, 0); collide_type = GetCollideType(victim); SetCollideType(victim, 0); // Start the respawn timer SetThingTimer(victim, wait_time); // Create a random powerup at the victim's position rval = Rand(); if (rval < 0.15) { CreateThing(powerup0, victim); } else if (rval < 0.35) { CreateThing(powerup1, victim); } else if (rval < 0.45) { CreateThing(powerup2, victim); } else if (rval < 0.46) { CreateThing(powerup3, victim); } else if(rval < 0.61) { CreateThing(powerup4, victim); } else if(rval < 0.66) { CreateThing(powerup5, victim); } else if(rval < 0.67) { CreateThing(powerup6, victim); } } else SetThingUserData(victim, health - damage); Return; # ........................................................................................ timer: victim = GetSenderRef(); // Respawn the victim (render it visible and enable it's collision switch) SetThingCurGeoMode(victim, geo_mode); SetCollideType(victim, collide_type); // Reset the victim's health SetThingUserData(victim, life); // Play the respawn sound PlaySoundThing(respawn_snd, victim, 1, 0, 8, 0x0); Return; end
I've tried it with simple variables and heaps, but both seem to be overridden by the next vase's class cog...
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)