Page 1 of 5
Rotating weapon help
Posted: July 9th, 2010, 9:33 am
by <LT>YosemiteSam[NL]
I have 1 weapon in my map which I want to rotate continiously.
I checked the box "rotate" in the entity window of the weapon but that doesn't work.
Can I do this by rotating the weapon around an origin or will that cause a script error when the weapon is picked up ?
Anyone have some ideas on this ?
Re: Rotating weapon help
Posted: July 9th, 2010, 10:00 am
by Rezil
If it's an entity you can give it a targetname and make it rotate by scripting(in theory, I haven't actually tried it).
Re: Rotating weapon help
Posted: July 9th, 2010, 1:48 pm
by <LT>YosemiteSam[NL]
I also thought about that but haven't tried it either.
But like I said you have to rotate it around an origin and I think when the weapon is picked up the script doesn't recognize the entity anymore, so it will give an error.
But enough theory .... I'll try it when I get home.
Re: Rotating weapon help
Posted: July 9th, 2010, 2:14 pm
by Rezil
Well you could make it seem like the player picked up the weapon - make a script_model, add a trigger_use_touch around it then give the player the weapon via script and hide the script_model. Then you could handle dropping the currently selected weapon, checking whether the player already has that weapon etc. all through a seperate .gsc.
Re: Rotating weapon help
Posted: July 9th, 2010, 9:39 pm
by <LT>YosemiteSam[NL]
thx rezil I'll sort that out later. But i have a different spawn problem which I also had 3 years ago,
I can respawn a weapon with scripting but but everytime it respawns the weapon falls to the floor/ground (I have suspended checked in the entity window of the weapon). I want it to be suspended aswell.
Second, I want the weapon I "drop" (when I pick up the spawnable weapon) to be gone after the spawnable weapon respawns.
To put it more clearly I hope
;
What's happening now;
- pick up spawnable weapon (which is suspended)
- current weapon replaces the spawnable weapon (and is suspended aswell)
- after X seconds weapon is respawned and drops to the floor
- The weapon which replaced the spawnable weapon is still there.
What I want to happen;
- pick up spawnable weapon (which is suspended)
- current weapon replaces the spawnable weapon (and is suspended aswell)
- after X seconds weapon is respawned (suspended) and replaces the suspended weapon
This is the gsc I use for the respawn;
Code: Select all
main()
{
WeaponRespawner("redeemer", 10);
}
// Create multiplayer weapons in Radiant as follows:
// Create weapons in the 2d window with right click "weapons" and select a weapon with _mp at the end which is available in mp
// Set the targetname to a value of your choice, e.g. "weapons" and use the same value to kick off your respawners
// Optional: Set count to the number of weapons that spawn at a time, e.g. 3 for three grenades at once
// Optional: set script_timescale to the time in seconds between respawns
// In your main script include the below functions and place an initial call to the WeaponRespawner in the main routine of your map
// A typically call would be: "WeaponRespawner("weapons", 5);" that will manage all entities with targetname weapons and a default respawn delay of 5 seconds
WeaponRespawner(targetname, defaultrespawndelay)
{
// by sentchy
weapons = getentarray("redeemer", "targetname");
if(weapons.size > 0)
{
for(i=0; i < weapons.size; i++)
{
if(!isdefined(weapons[i].script_timescale))
weapons[i].script_timescale = defaultrespawndelay;
// kick off a thread to listen for when the item gets picked up
weapons[i] thread weapon_think(weapons[i].script_timescale);
}
}
}
// self = weapon reference
weapon_think(delaytime)
{
// capture important weapon data first to allow us to respawn them
classname = self.classname;
model = self.model;
count = self.count;
org = self.origin;
angles = self.angles;
targetname = self.targetname;
// Wait till the weapon gets picked up
self waittill("trigger");
// Wait the delay before respawn
wait delaytime;
// respawn the weapon
weapon = spawn(classname, org);
weapon.angles = angles;
weapon.count = count;
weapon setmodel(model);
weapon.script_timescale = delaytime;
weapon.targetname = targetname;
weapon playsound("spawnsound");
// Kick off a new thread with the new weapon and kill the old one
weapon thread weapon_think(delaytime);
}
Re: Rotating weapon help
Posted: July 10th, 2010, 1:01 pm
by Rezil
Add this line of code under "targetname = self.targetname;":
Then, modify the spawn command. Instead of
use
Code: Select all
weapon = spawn(classname, org, flags);
and test.
Re: Rotating weapon help
Posted: July 10th, 2010, 1:17 pm
by <LT>YosemiteSam[NL]
THX REZ ! works like a charm
Now I want the weapon which i left when picking up the spawnable weapon to be delted before/during the respawn.
Drof told me a few years back to do it with "entity delete();" or "entity destroy();"
I tried that but to no avail, any ideas ?
Re: Rotating weapon help
Posted: July 10th, 2010, 1:45 pm
by Rezil
self delete(); after self waittill("trigger");
Re: Rotating weapon help
Posted: July 10th, 2010, 1:56 pm
by <LT>YosemiteSam[NL]
I tried that but I get a script error (when picking up the weapon in game);
Code: Select all
removed entity is not an entity ??
If it is removed don't wine about it
Re: Rotating weapon help
Posted: July 10th, 2010, 2:11 pm
by Rezil
Hm, not an entity? Well if you picked up the weapon and replaced it with another, it should still register as an entity. Try self hide(); and see if you can still pick it up.
Re: Rotating weapon help
Posted: July 10th, 2010, 2:45 pm
by Drofder2004
Why delete it? Just use the TriggerOff and TriggerOn functions from utility.
Combined with a loop.
Unless you plan on adding multiple new weapons, then there is no point in creating a template function.
Re: Rotating weapon help
Posted: July 10th, 2010, 2:57 pm
by Rezil
Unless you plan on adding multiple new weapons, then there is no point in creating a template function.
I think that's what he's going for. Multiple arrays of weapons and just calling the same function on them. I almost never use TriggerOff but I suppose it would work here.
Re: Rotating weapon help
Posted: July 10th, 2010, 4:25 pm
by <LT>YosemiteSam[NL]
Rezil wrote:Unless you plan on adding multiple new weapons, then there is no point in creating a template function.
I think that's what he's going for. Multiple arrays of weapons and just calling the same function on them. I almost never use TriggerOff but I suppose it would work here.
Yep, that's what I want to make, a lot of weapons with the same function.
That self hide(); gives the same error. also triedit with model but that doesn't work.
Re: Rotating weapon help
Posted: July 10th, 2010, 4:28 pm
by Rezil
self TriggerOff();
And add #include maps\mp\_utility; to the very top of the script.
Re: Rotating weapon help
Posted: July 10th, 2010, 4:33 pm
by <LT>YosemiteSam[NL]
Rezil wrote:self TriggerOff();
And add #include maps\mp\_utility; to the very top of the script.
Did that now I get this errror;