Page 1 of 2

Making weapons respawn in mp map ?

Posted: September 12th, 2007, 10:20 am
by <LT>YosemiteSam[NL]
Does someone know how to make weapons respawn in a mp_map ?
And can you make it so that when you pick the weapon up the weapon you drop will fall onto the floor instead of replacing the one you pick up?

Posted: September 12th, 2007, 3:19 pm
by [SoE]_Zaitsev
From all the MP maps I have seen is that whenever you pick up a weapon which has been placed there by the creator of the map it will disappear.

That's just one point from me, I'm no mapper. There must be one here who knows more than me.

Posted: September 13th, 2007, 2:27 am
by Soviet
in cod1 radiant you select the gun, press n to bring up the entity editor, and check the respawn box, i think it is the same in cod2. As for the 2nd question, don't think it is possible.

Posted: September 13th, 2007, 6:58 am
by JDogg
I'm no mapper (and I wont pretend to be) but cant you do it with triggers and some scripting??

Posted: September 13th, 2007, 9:18 am
by <LT>YosemiteSam[NL]
Thx, but I found a way (opened the gsc of a map with respawnable weapons :) ) to respawn the weapon, almost totaly done with scripting.
And for that second question, can't be done I guess :?

Posted: September 14th, 2007, 3:36 pm
by All-Killer
Actually its possible

In the PAM mod you can drop the weapon on the ground. Look in the PAM iwd for the script.

Posted: September 14th, 2007, 7:33 pm
by [SoE]_Zaitsev
True, but once you pick it up it it disappears.

If I drop the MP44 on the ground, and a player who has an MP44 walks over it, simply picks it up as ammo.

It doesn't work like Sam wants it to work.

Posted: September 15th, 2007, 11:49 am
by All-Killer
Hmm true. Maby drofder knows a way? If it is possible to spawn a trigger trough script and place that around the weapon it could check if you already have a mp44, then leave it on the ground, otherwise pick it up.

Posted: September 15th, 2007, 1:24 pm
by Nightmare
I am not 100% sure, but I do not think that is possible. It might be, but you are going to have to dig pretty deep.

Posted: September 15th, 2007, 7:26 pm
by <LT>YosemiteSam[NL]
Ok, when it takes too much time and effort I won't wurry about it anymore :)

However, when you pick up the spawnable weapon, the weapon in your hand takes the place of that weapon. Does that weapon dissapear in a while or does it stay there till the end of the map ?
And if it stays there is it possible to let it dissapear after let's say 1 minute ?

For the spawnable weapon I have this script;

Code: Select all

WeaponRespawner(targetname, defaultrespawndelay)
{
weapons = getentarray(targetname, "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;

// Kick off a new thread with the new weapon and kill the old one
weapon thread weapon_think(delaytime);
}
I think the answer to my question is in there somewhere :wink: but I can't figure out where ?

Posted: September 16th, 2007, 1:50 am
by Drofder2004
I cba to read backwards to find your question you seek... but I will guide you through the code and see if I can help...

Ok, taking the code line/section at a time...

Code: Select all

1.
WeaponRespawner(targetname, defaultrespawndelay)
{
Ok, first off, the FUNCTION is called "WeaponRespawner".
Inside the brackets the function ask for two VARIABLES; "targetname" and "defaultrespawndelay" (I will explain each variable when I get to them in the next section.)

Code: Select all

2.
weapons = getentarray(targetname, "targetname");
This will find all ENTITIES with the targetname you assign when you call the function (See 1.)

Code: Select all

3.
if(weapons.size > 0)
{
This will check to find out if any entities exist, if true, continue. (Size is not a measurement, but a count).

Code: Select all

4.
for(i=0; i < weapons.size; i++)
{
This creates a looping thread which will be called the same amount of times as the amount of weapons there are.

Code: Select all

5.
if(!isdefined(weapons[i].script_timescale))
   weapons[i].script_timescale = defaultrespawndelay;
This will check the weapon (entity) if the variable '.script_timescale' exists. If it does not exist, then a default time you provided (See 1.) will be used.

Code: Select all

6.
weapons[i] thread weapon_think(weapons[i].script_timescale);
This will send the entity into a new function (See 7.) to check for when it gets picked up, the variable which was assigned earlier (See 5.) is also sent.

Code: Select all

}
}
}
Clsoe all open brackets.

Code: Select all

7.
weapon_think(delaytime)
{
New function for checking when a weapon is picked up.

Code: Select all

8.
classname = self.classname;
model = self.model;
count = self.count;
org = self.origin;
angles = self.angles;
targetname = self.targetname;
The function then records all variables for later recall.
The following is collected, classname (determines which type of entity it is), model (the model of the entity), count (not sure what this for), origin (the coordinates of the entity), angles (the angles of the entity), targetname (the name which has been assigned to the entity).

Code: Select all

9.
self waittill("trigger");
Wait until the trigger is used (weapon is picked up),

Code: Select all

10.
wait delaytime;
Wait the delaytime before continuing the function.

Code: Select all

11.
weapon = spawn(classname, org);
Spawn a NEW entity, with the same classname and origin.

Code: Select all

12.
weapon.angles = angles;
weapon.count = count;
weapon setmodel(model);
weapon.script_timescale = delaytime;
weapon.targetname = targetname;
Assign the new entity with same values of the entity recorded earlier.

Code: Select all

13.
weapon thread weapon_think(delaytime);
}
Restart this thread. Once this is called, the current thread ends and the new one begins.

Hopefully something in their answers you question.

Posted: September 17th, 2007, 2:52 pm
by <LT>YosemiteSam[NL]
Thx, Drof. But my answer isn't in there. What I do know is I have to put a line in between code 10 and 11 which makes the weapon which the player switched the spawnable one with dissapear before spawning the new one.

Btw, count = amount of bullets for the spawnable weapon (to my knowledge).

Posted: September 17th, 2007, 3:12 pm
by Drofder2004
Ok, give me a step-by-step, as detailed as possible on what you want to happen. I'll see if I can fill in the gaps.

Posted: September 17th, 2007, 4:18 pm
by <LT>YosemiteSam[NL]
ok;

1 - Player picks up spawnable weapon. (Panzershreck in this case)
2 - The weapon he was holding at the moment of pick up replaces the spawnable weapon.

This part works like a charm but I want also the following thing to happen,

3 - The weapon the player was holding now lies on the spot where the panzershreck will spawn again.
4 - I want that weapon to dissapear before the panzershreck respawns.

I think the command for that should go between 10 and 11, should be something like this;

Code: Select all

10. 
wait delaytime;

Code: Select all

Remove weapon ???? which command

Code: Select all

11. 
weapon = spawn(classname, org);

Posted: September 18th, 2007, 12:01 am
by Drofder2004
delete(); is the command you seek.

Just before the weapon respawns, IF the weapon is still in the same place (same origin), then "entity delete();"

if delete doesn't work, try destroy(); I often get these 2 muddled :)