Page 1 of 1

scripting help

Posted: January 3rd, 2011, 3:36 pm
by pedram_manowar
hi guys first of all happy new year
second sorry for my bad english :?:

i need a script wich i can teleport myself by pressing a key
for example when i look at the top of the house on backlot or anywhere else when i press that button(for example i bind the key for G) when i press G i teleport myself there.
is there any way to do that?

this is what i have found on one of codjumper old mods
but its not working or i dont know how to make it work :oops: (im noob with scripting)

Code: Select all

onPlayerConnect()

for(;;)
        {
                level waittill("connecting", player);
                player thread onPlayerSpawned();
            
        }
}

onPlayerSpawned()
{                                                                                                                                                                                                                                                                 
        self endon("disconnect");
   
        for(;;)
        {                                                                                                           
                self waittill("spawned_player");
                self thread doTeleport();                                                                             
        }
}

doTeleport()
{
        self endon ( "disconnect" );
        self endon ( "death" );
	self notifyOnPlayerCommand("Nightvision", "+actionslot 1");

        for(;;)
        {
		self waittill( "Nightvision" );
		if( self GetStance() == "stand") 
		{	      
			self beginLocationselection( "map_artillery_selector", true, ( level.mapSize / 5.625 ) );
         		self.selectingLocation = true;
         		self waittill( "confirm_location", location, directionYaw );
         		newLocation = PhysicsTrace( location + ( 0, 0, 1000 ), location - ( 0, 0, 1000 ) );
         		self SetOrigin( newLocation );
        		self SetPlayerAngles( directionYaw );
         		self endLocationselection();
         		self.selectingLocation = undefined;
		}
	}
}
if anyone can make it work for me i will thank him forever :D

Re: scripting help

Posted: January 3rd, 2011, 4:32 pm
by Drofder2004
You cannot detect keypresses by letter, you can only use functions such as "attackButtonPressed()", "useButtonPressed()" and a few others.

Re: scripting help

Posted: January 3rd, 2011, 4:54 pm
by Rezil
Infinite loop:
{
- Get the angles of where you're currently looking at(vector).
- Do bullettrace to get the first thing that's intersected by the vector you got before(point)
}
- Infinite loop in a seperate thread called on a player to check when he presses a certain button(You're limited to use, melee and attack IIRC).
- When the player presses the button, set his origin to that point.

Re: scripting help

Posted: January 3rd, 2011, 5:45 pm
by pedram_manowar
guys thanks but thats not what i mean
i mean when i look at anywhere on map all things you says happend automatically and when i press for example G i teleport myself there can you guys edit the code that i say on first post and make it work (my head is going to explode) pls?

Re: scripting help

Posted: January 3rd, 2011, 6:05 pm
by Pedsdude
pedram_manowar wrote:guys thanks but thats not what i mean
i mean when i look at anywhere on map all things you says happend automatically and when i press for example G i teleport myself there can you guys edit the code that i say on first post and make it work (my head is going to explode) pls?
Drofder has already said that you can't detect specific key presses - you can only detect if they've done certain actions, for example use, melee, shoot, etc.

Re: scripting help

Posted: January 3rd, 2011, 6:42 pm
by F |Madness| U
In which case you'd have to bind G as `Use`, and make it so that it detects Use as the button to perform the teleport.

Either way he's saying that he can't code and wants someone like Drofder or another coder to do it for him, just that he simply already has a partially made code.

Re: scripting help

Posted: January 4th, 2011, 1:06 am
by IzNoGoD

Code: Select all

main()
{
	thread waitforconnect();
}
waitforconnect()
{
	for(;;)
	{
		level waittill("connecting",player);
		player thread onconnect();
	}
}

onconnect()
{
	self endon("disconnect");
	for(;;)
	{
		self waittill("spawned_player");
		self thread onspawn();
	}
}

onspawn()
{
	self endon("disconnect");
	self endon("killed_player");//or "death" or whatever
	self endon("spawned_player");
	teleported=false;
	for(;;)
	{
		if(self istrowingnade()&&!teleported)
		{
			teleported=true;
			vec=maps\mp\_utility::vectorscale(anglestoforward(self getplayerangles()),10000);
			trace=bullettrace(self geteye(),self geteye()+vec,false,undefined);
			telepoint=trace["position"]+(0,0,30);
			time=distance(telepoint,self geteye())/200;
			self moveto(telepoint,time);
			wait time;
		}
		else
			teleported=false;
		wait 0.05;
	}
}


istrowingnade()
{
	switch(self getcurrentweapon())
	{
		case "frag_grenade_american_mp":
		case "smoke_grenade_american_mp":
		case "frag_grenade_british_mp":
		case "smoke_grenade_british_mp":
		case "frag_grenade_russian_mp":
		case "smoke_grenade_russian_mp":
		case "frag_grenade_german_mp":
		case "smoke_grenade_german_mp":
			return true;
		default:
			return false;
	}
}
Untested code, cod2 syntax, cod2 weapons and cod2 notifies.
You will have to adapt this code to cod4, if this is meant for cod4.