Making weapons respawn in mp map ?
Moderator: Core Staff
-
- Core Staff
- Posts: 2155
- Joined: December 7th, 2004, 2:07 am
- Location: Netherlands
- Contact:
-
- Core Staff
- Posts: 2155
- Joined: December 7th, 2004, 2:07 am
- Location: Netherlands
- Contact:
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
-
- Core Staff
- Posts: 2155
- Joined: December 7th, 2004, 2:07 am
- Location: Netherlands
- Contact:
Code: Select all
main()
{
maps\mp\_load::main();
thread spin();
thread spin2();
thread spin3();
thread spin4();
thread spin5();
thread spin6();
thread spin7();
thread spin8();
WeaponRespawner("weapons", 50);
ambientPlay("ambient_mp_FEI");
game["allies"] = "british";
game["axis"] = "german";
game["british_soldiertype"] = "airborne";
game["british_soldiervariation"] = "normal";
game["german_soldiertype"] = "fallschirmjagergrey";
game["german_soldiervariation"] = "normal";
game["attackers"] = "allies";
game["defenders"] = "axis";
}
spin()
{
door = getent("door","targetname");
door1 = getent("door1","targetname");
trigger = getent("door_trig","targetname");
while(1)
{
trigger waittill ("trigger");
door rotateyaw(90,2);
door1 rotateyaw(-90,2);
door playsound ("doorsound");
door1 waittill("rotatedone");
wait 2;
door rotateto((0, 0, 0), 2);
door1 rotateto((0, 0, 0), 2);
door playsound ("doorsound");
door1 waittill("rotatedone");
}
}
spin2()
{
door = getent("door","targetname");
door1 = getent("door1","targetname");
trigger = getent("doorinside_trig","targetname");
while(1)
{
trigger waittill ("trigger");
door rotateyaw(-90,2);
door1 rotateyaw(90,2);
door playsound ("doorsound");
door1 waittill("rotatedone");
wait 2;
door rotateto((0, 0, 0), 2);
door1 rotateto((0, 0, 0), 2);
door playsound ("doorsound");
door1 waittill("rotatedone");
}
}
spin3()
{
door2 = getent("door2","targetname");
trigger = getent("door2_trig","targetname");
while(1)
{
trigger waittill ("trigger");
door2 rotateyaw(-90,2);
door2 playsound ("doorsound");
door2 waittill("rotatedone");
wait 2;
door2 rotateto((0, 0, 0), 2);
door2 playsound ("doorsound");
door2 waittill("rotatedone");
}
}
spin4()
{
door2 = getent("door2","targetname");
trigger = getent("door2inside_trig","targetname");
while(1)
{
trigger waittill ("trigger");
door2 rotateyaw(90,2);
door2 playsound ("doorsound");
door2 waittill("rotatedone");
wait 2;
door2 rotateto((0, 0, 0), 2);
door2 playsound ("doorsound");
door2 waittill("rotatedone");
}
}
spin5()
{
door3roof = getent("door3roof","targetname");
trigger = getent("door3roof_trig","targetname");
while(1)
{
trigger waittill ("trigger");
door3roof rotateyaw(-90,2);
door3roof playsound ("doorsound");
door3roof waittill("rotatedone");
wait 2;
door3roof rotateto((0, 0, 0), 2);
door3roof playsound ("doorsound");
door3roof waittill("rotatedone");
}
}
spin6()
{
door3roof = getent("door3roof","targetname");
trigger = getent("door3roofinside_trig","targetname");
while(1)
{
trigger waittill ("trigger");
door3roof rotateyaw(90,2);
door3roof playsound ("doorsound");
door3roof waittill("rotatedone");
wait 2;
door3roof rotateto((0, 0, 0), 2);
door3roof playsound ("doorsound");
door3roof waittill("rotatedone");
}
}
spin7()
{
door4 = getent("door4","targetname");
door5 = getent("door5","targetname");
trigger = getent("door45_trig","targetname");
while(1)
{
trigger waittill ("trigger");
door4 rotateyaw(90,2);
door5 rotateyaw(-90,2);
door4 playsound ("doorsound");
door5 waittill("rotatedone");
wait 2;
door4 rotateto((0, 0, 0), 2);
door5 rotateto((0, 0, 0), 2);
door4 playsound ("doorsound");
door5 waittill("rotatedone");
}
}
spin8()
{
door4 = getent("door4","targetname");
door5 = getent("door5","targetname");
trigger = getent("door45inside_trig","targetname");
while(1)
{
trigger waittill ("trigger");
door4 rotateyaw(-90,2);
door5 rotateyaw(90,2);
door4 playsound ("doorsound");
door5 waittill("rotatedone");
wait 2;
door4 rotateto((0, 0, 0), 2);
door5 rotateto((0, 0, 0), 2);
door4 playsound ("doorsound");
door5 waittill("rotatedone");
}
}
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;
entity delete();
// 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);
}
To recap; I want the weapon, which the player leaves after picking up the spawnable one, to be deleted before respawning the spawnable one.
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Ok, theres a couple of things which I will point out but not solve yet as I need to look into it a bit further...
First.
As far as I am aware, "weapons" is not a valid targetname. Every weapon in the game, has its own targetname, and I am not sure 'weapons' can be used, but again, I need to look into it further.
Second.
entity must refer to a entity, not literally be called entity. At the moment, the game will not understand what entity is. Entity must be directly related to something.
---
Could you please give me the name of the mod/map that contains the GSC so I can look at the full text and how they used it, it will certainly help me understand exactly how they reference the weapons.
---
First.
Code: Select all
WeaponRespawner("weapons", 50);
Second.
Code: Select all
entity delete();
---
Could you please give me the name of the mod/map that contains the GSC so I can look at the full text and how they used it, it will certainly help me understand exactly how they reference the weapons.
---
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
-
- Core Staff
- Posts: 2155
- Joined: December 7th, 2004, 2:07 am
- Location: Netherlands
- Contact:
That seems to be the problem, it has to refer to the weapon dropped by the player who picks up the spawnable weapon.entity must refer to a entity, not literally be called entity. At the moment, the game will not understand what entity is. Entity must be directly related to something.
Code: Select all
WeaponRespawner("weapons", 50);
The map which uses this code is called "Fargo"
Here is the gsc of that map;
Code: Select all
main()
{
setExpFog(.00015, 0.03, .03, .03, 0);
maps\mp\mp_fargo_fx::main();
maps\mp\_load::main();
//Set background ambient noise
ambientPlay("ambient_mp_fargo");
//Soldier Settings
game["allies"] = "american";
game["axis"] = "german";
game["attackers"] = "allies";
game["defenders"] = "axis";
game["american_soldiertype"] = "africa";
game["german_soldiertype"] = "africa";
//Initialize the weapon respawner.
WeaponRespawner("weapons", 60);
WeaponRespawner("weapons_gunroom", 60);
thread theDOORS(2);
}
theDOORS(howoften)
{
// set howoften to 2 for a 50/50 display or higher number for less often.
while(1)
{
for(d=0; d < 2; d++)
{
if(d == 0){
doors = getentarray("door_move_x", "targetname");
dir = "movex";
}else{
doors = getentarray("door_move_y", "targetname");
dir = "movey";
}
if(doors.size > 0)
{
for(i=0; i < doors.size; i++)
{
this_num = randomint(howoften);
if(this_num == 0)
{
if(!isdefined(doors[i].isopen))
{
doors[i].isopen = "true";
}
if(doors[i].isopen == "true")
{
closedoor(doors[i], dir, 44);
}
else
{
opendoor(doors[i], dir, 44);
}
}
}
}
}
// this_wait = randomint(4);
// this_wait = (this_wait + 1) * 30;
// iprintlnbold(this_wait);
// wait (this_wait);
// causes a random delay of 30, 60, 90, or 120 seconds
wait (30);
}
}
closedoor(door, dir, wid){
if(dir == "movex")
{
door movex(wid, 2, .5, .5);
}else{
door movey(wid, 2, .5, .5);
}
door.isopen = "false";
}
opendoor(door, dir, wid){
if(dir == "movex")
{
door movex(0-wid, 2, .5, .5);
}else{
door movey(0-wid, 2, .5, .5);
}
door.isopen = "true";
}
// 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(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);
}
-
- CJ Worshipper
- Posts: 383
- Joined: December 16th, 2005, 6:38 pm
-
- Core Staff
- Posts: 2155
- Joined: December 7th, 2004, 2:07 am
- Location: Netherlands
- Contact:
Who is online
Users browsing this forum: No registered users and 16 guests