Rotating weapon help

Have questions about CoD2 mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

User avatar
<LT>YosemiteSam[NL]
Core Staff
Core Staff
Posts: 2155
Joined: December 7th, 2004, 2:07 am
Location: Netherlands
Contact:

Rotating weapon help

Post by <LT>YosemiteSam[NL] » July 9th, 2010, 9:33 am

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 ?

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Rotating weapon help

Post by Rezil » July 9th, 2010, 10:00 am

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).
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
<LT>YosemiteSam[NL]
Core Staff
Core Staff
Posts: 2155
Joined: December 7th, 2004, 2:07 am
Location: Netherlands
Contact:

Re: Rotating weapon help

Post by <LT>YosemiteSam[NL] » July 9th, 2010, 1:48 pm

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. :)

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Rotating weapon help

Post by Rezil » July 9th, 2010, 2:14 pm

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.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
<LT>YosemiteSam[NL]
Core Staff
Core Staff
Posts: 2155
Joined: December 7th, 2004, 2:07 am
Location: Netherlands
Contact:

Re: Rotating weapon help

Post by <LT>YosemiteSam[NL] » July 9th, 2010, 9:39 pm

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);
}

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Rotating weapon help

Post by Rezil » July 10th, 2010, 1:01 pm

Add this line of code under "targetname = self.targetname;":

Code: Select all

flags = self.spawnflags;
Then, modify the spawn command. Instead of

Code: Select all

weapon = spawn(classname, org);
use

Code: Select all

 weapon = spawn(classname, org, flags);
and test.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
<LT>YosemiteSam[NL]
Core Staff
Core Staff
Posts: 2155
Joined: December 7th, 2004, 2:07 am
Location: Netherlands
Contact:

Re: Rotating weapon help

Post by <LT>YosemiteSam[NL] » July 10th, 2010, 1:17 pm

THX REZ ! works like a charm :D

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 ?

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Rotating weapon help

Post by Rezil » July 10th, 2010, 1:45 pm

self delete(); after self waittill("trigger");
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
<LT>YosemiteSam[NL]
Core Staff
Core Staff
Posts: 2155
Joined: December 7th, 2004, 2:07 am
Location: Netherlands
Contact:

Re: Rotating weapon help

Post by <LT>YosemiteSam[NL] » July 10th, 2010, 1:56 pm

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 :wink:

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Rotating weapon help

Post by Rezil » July 10th, 2010, 2:11 pm

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.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Rotating weapon help

Post by Drofder2004 » July 10th, 2010, 2:45 pm

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.
Image
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

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Rotating weapon help

Post by Rezil » July 10th, 2010, 2:57 pm

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.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
<LT>YosemiteSam[NL]
Core Staff
Core Staff
Posts: 2155
Joined: December 7th, 2004, 2:07 am
Location: Netherlands
Contact:

Re: Rotating weapon help

Post by <LT>YosemiteSam[NL] » July 10th, 2010, 4:25 pm

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.

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Rotating weapon help

Post by Rezil » July 10th, 2010, 4:28 pm

self TriggerOff();

And add #include maps\mp\_utility; to the very top of the script.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
<LT>YosemiteSam[NL]
Core Staff
Core Staff
Posts: 2155
Joined: December 7th, 2004, 2:07 am
Location: Netherlands
Contact:

Re: Rotating weapon help

Post by <LT>YosemiteSam[NL] » July 10th, 2010, 4:33 pm

Rezil wrote:self TriggerOff();

And add #include maps\mp\_utility; to the very top of the script.
Did that now I get this errror;
You do not have the required permissions to view the files attached to this post.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests