spawn without anygun?

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
Aprop
Major
Posts: 291
Joined: Mon Nov 17, 2008 3:40 pm

spawn without anygun?

Post by Aprop »

Hello
I want spawn players on my dm map without any weapons... how can do it? I tried replace "waittil death" with "local.player.health <= 0" in loop, but it...dont work? Help!
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

Because you need to take their weapons away at spawn, not at death. Detecting player spawning isn't easy, though. Jv_map developed a reliable method, though: spawn a trigger_multiple and glue it to the player. When it triggers, you can assume the player is physically ingame and you can take away their weapons.
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
Aprop
Major
Posts: 291
Joined: Mon Nov 17, 2008 3:40 pm

Post by Aprop »

I tried do this, but my trigger trigg's every 1 second.... should i use "istouching" ? Nvm, i need jv_map scr, can you show me it?
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

Jv didn't give me a script back in the time when I was his Padawan. I had to use my own Force. :)

But anyway, here's some code off the top of my head. This is how the trigger should be spawned:

Code: Select all

local.player.trigger = spawn trigger_multiple setthread "path/to/your/script.scr::player_spawn" // the setthread parameter's value is the thread that will be called when the trigger goes off
local.player.trigger.player = local.player // this is essential to make sure we detect the right player!
local.player.trigger wait 0.05 // makes it go off every frame (server runs at a constant 20FPS)
local.player.trigger setsize ( -15 -15 0 ) ( 15 15 95 ) // because it's nice to encompass the entire player :)
local.player.trigger glue local.player // makes the trigger follow the player everywhere
And the player_spawn thread:

Code: Select all

player_spawn:
	local.player = parm.other // save off the triggering entity, it may change in the next frame
	if (local.player != self.player)
		// someone else triggered the trigger
		end
	self delete // we don't need the trigger anymore
	waitframe // wait a bit, otherwise the inventory might not be initialized yet and we won't take anything away
	local.player takeall
end
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
Aprop
Major
Posts: 291
Joined: Mon Nov 17, 2008 3:40 pm

Post by Aprop »

So there is always new trigger for every spawn? Ill try tis


Yea, it work... i need fix it lil cuz when i change team i resp with weapons, but its quite simple job... but there is another problem.. look:

Code: Select all

SV_FindIndex: overflow error (max=64) when creating "MG42"
Weap's limit? To fix it i need remove <some> weapons, for eg not used, everytime script-taked from player colt42....Or maybe can i change max to 128?
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Hmmm can't remember you asking rook ;)

There's a somewhat better method for detecting spawn, I learned it from Snake from Moh:reloaded. Basically you change the value of a player's maxhealth (anything other than 100), then when he spawns the game will reset that value to 100. You can detect this with a script. See my squadmaker mod for an example. Makes it a bit cleaner than the trigger method though that will work fine too.

Aprop, that error is an ubersound error (too many sound aliases). You may need to clean out your main folder (move currently unused maps/mods to a different folder and retry).
Image
$oldier Of Ra
Lieutenant Colonel
Posts: 404
Joined: Sun Oct 16, 2005 7:16 pm
Location: Belgium
Contact:

Post by $oldier Of Ra »

Detecting spawns isn't easy with any method I think. Even when using that health method. You need to apply the health change to all new players and then check it. Perhaps something like this:

Code: Select all

while(1)
{
for (local.a = 1; local.a <= $player.size; local.a++)
{
local.player = $player[local.a]
   if (isAlive local.player == 1 && local.player.fixed_health == NIL)
   {
   local.player.fixed_health = 1
   local.player health 120
   }
   if (isAlive local.player == 1 && local.player.fixed_health == 1 && local.player.health <= 100)
   {
   local.player thread just_spawned
   }
}
wait 0.2
}
If I recall correctly, sorrid has made a script which detects spawns, team-swaps etc... called gametype helper.
Our official website: http://www.mohaairborne.co.cc
(Still accessible through http://mohaaclantb.tk and http://users.skynet.be/mohaaclantb/)

For all your bot needs!!!!

$oldier Of Ra.
Aprop
Major
Posts: 291
Joined: Mon Nov 17, 2008 3:40 pm

Post by Aprop »

Aprop wrote:

Code: Select all

SV_FindIndex: overflow error (max=64) when creating "MG42"
jv_map wrote:
Aprop, that error is an ubersound error (too many sound aliases). You may need to clean out your main folder (move currently unused maps/mods to a different folder and retry).
Huh? ITS a ubersound error? No, it appears when i spawn 64th weapon on map.... using spawn command...
Last time (i added some weapons to map) it shows every time when i first change team to opposite... in this case i have for ex. Colt45 not MG42...
Herr Klugscheisser
Lance Corporal
Posts: 21
Joined: Thu Mar 17, 2005 1:14 pm

Post by Herr Klugscheisser »

A method SorridStroker taught me was to rescript the torso state (what SoR mentioned).

Code: Select all

state STAND
{

	states
	{
		PLAYER_SPAWNED	: NEW_WEAPON
	}

}

state PLAYER_SPAWNED
{
	movetype legs

	entrycommands
	{
	//look everyone I have spawned!!
               // exec my_script_I_have_just_spawned
	commanddelay 0.05 forcetorsostate "STAND_PROPER"
	}


}

//==============================================================================
//
// Stand (really means not doing an action)
//
//==============================================================================

state STAND_PROPER
{
	movetype legs

	camera behind

	entrycommands
	{
		viewmodelanim idle
	}
	
	action
	{
		none				: default // no torso animation
	}

	states
	{
		KILLED				: KILLED
		PAIN				: PAIN

You would then have to change all the original STANDs to STAND_PROPER (or whatever you call it). I've used it for a couple years and seems to work well.
$oldier Of Ra
Lieutenant Colonel
Posts: 404
Joined: Sun Oct 16, 2005 7:16 pm
Location: Belgium
Contact:

Post by $oldier Of Ra »

Ahar :D I finished my own fool-proof spawn detecting method. It uses the states but there's no need to rescript it! If you still need it Aprop then I'll post it.
Our official website: http://www.mohaairborne.co.cc
(Still accessible through http://mohaaclantb.tk and http://users.skynet.be/mohaaclantb/)

For all your bot needs!!!!

$oldier Of Ra.
Aprop
Major
Posts: 291
Joined: Mon Nov 17, 2008 3:40 pm

Post by Aprop »

I already using trigger method, but you can show your own...
$oldier Of Ra
Lieutenant Colonel
Posts: 404
Joined: Sun Oct 16, 2005 7:16 pm
Location: Belgium
Contact:

Post by $oldier Of Ra »

Find the RAISE_WEAPON state in the mike_torso state and add an exec line in the entrycommands; like so:

Code: Select all

state RAISE_WEAPON
{
	movetype legs

	entrycommands
	{
		viewmodelanim pullout

		// just to make sure nothing funky's 
		// attached that shouldn't be.
		correctweaponattachments
		exec global/states/player_spawn.scr "spawned"
	}

	states
	{
		RAISE_PISTOL		: IS_NEW_WEAPONCLASS "mainhand" "pistol"
		RAISE_RIFLE			: IS_NEW_WEAPONCLASS "mainhand" "rifle"
		RAISE_GRENADE		: IS_NEW_WEAPONCLASS "mainhand" "grenade"
		RAISE_SMG			: IS_NEW_WEAPONCLASS "mainhand" "smg"
		RAISE_MG			: IS_NEW_WEAPONCLASS "mainhand" "mg"
//		RAISE_PISTOL		: IS_NEW_WEAPONCLASS "mainhand" "item" // hold all items like a pistol for now
		RAISE_HEAVY			: IS_NEW_WEAPONCLASS "mainhand" "heavy"
		RAISE_PAPERS		: IS_NEW_WEAPON "mainhand" "Papers"
		
//		RAISE_RIFLE			: default
		RAISE_NOANIM		: default
	}
}
Now in that global/states/player_spawn.scr script, put this (this is an edited simpler and smaller version of mine, I don't think you need to have all the stuff I record from the states :P):

Code: Select all

// 
// ----------------------------
// NEW PLAYER VARS
// ---------------
//
// JUST SPAWNED:
// This variable gets set to 1 when the player has just spawned and
// back to 0 after max 5 seconds!
//
// Access: <player_alias>.jspawned
// 
// USEFUL SCRIPTS
// ---------------
// Self is the player in question in the following scripts:
//
// global/states/just_spawned.scr - gets run when a player has just spawned
//
// ----------------------------

//-----------------------------------
main local.dead_or_alive:

	if (self != NULL)
	{
		if (isAlive self && self.status != "alive" && local.dead_or_alive == "spawned" && self.max_health == 100.000)
		{
			self.status = "alive"
			self.jspawned = 1
			// Secondary checking measure; fake health trick by jv and snake!
			self.fake_max_health = 100.0100
			self.max_health = self.fake_max_health

			self thread follow_player
		}
	}

end

//-----------------------------------
follow_player:

	if (self.followed == 1)
		end
	else
		self.followed = 1

	local.time = 0
	local.team = self.dmteam
	local.num = self.entnum

	// *****************************************************
	// Follow the player for his first 5 seconds
	// *****************************************************

	self exec global/states/just_spawned.scr

	while ( self != NIL && self != NULL && self.health >= 96 && local.time <= 5.00)
	{
		waitframe
		local.time += 0.05
	}
	// *****************************************************
	

	//-------------------------------------------
	// player hasn't "just" spawned anymore
	//-------------------------------------------
if ( !(isAlive self) || self == NULL || self == NIL || self.dmteam != local.team )
		{
// normally the status "killed" also gets set by exec from the states but 
// let's keep it simple
		  self.status = "killed"
			self.followed = NIL
			self.jspawned = 0
			end
		}	

	// Or he survived the first 5 seconds of his current life!
self.jspawned = 0

	// ***************************************************
	// Follow the player until his playing is interrupted by: death, teamswap, left server...
	// ***************************************************
	while ( self != NULL && self != NIL && self.status != "killed" && self.dmteam == local.team && isAlive self && self.max_health == self.fake_max_health )
	{
		waitframe
	}
// ***************************************************

	//-----------------------------------------------
	// Player isn't being followed anymore...
	//-----------------------------------------------

	if ( !(isAlive self) || self == NULL || self == NIL || self.dmteam != local.team )
	{
// normally the status "killed" also gets set by exec from the states but 
// let's keep it simple
		self.status = "killed"
		self.followed = NIL

		end
	}

end
Make another script in global/states/ called just_spawned.scr and put this in it:

Code: Select all

main

println "Client (ID " self.entnum ") has just spawned!!"

end

Now edit that just_spawned script any way you like, it gets run everytime a player spawns!! Leave the println in it to see for yourself how accurate it is ;)

Increase the waits in those 2 loops if you wish (don't forget about the local.time var if you do!), but this script only gets run each time a player raises a weapon and only continues (else it ends) if a player raises the first weapon of his current lifetime (meaning he just spawned).

Cheers!! :)

(It might be a bit less accurate because I left out the exec from the KILLED state to set the players' status to "killed")
Our official website: http://www.mohaairborne.co.cc
(Still accessible through http://mohaaclantb.tk and http://users.skynet.be/mohaaclantb/)

For all your bot needs!!!!

$oldier Of Ra.
Post Reply