scripting help

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

Moderator: Core Staff

Post Reply
pedram_manowar
CJ Wannabe
CJ Wannabe
Posts: 4
Joined: September 27th, 2010, 6:56 am
Gamertag: +:|M.VIPER|:+â„¢
Contact:

scripting help

Post by pedram_manowar » January 3rd, 2011, 3:36 pm

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

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

Re: scripting help

Post by Drofder2004 » January 3rd, 2011, 4:32 pm

You cannot detect keypresses by letter, you can only use functions such as "attackButtonPressed()", "useButtonPressed()" and a few others.
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: scripting help

Post by Rezil » January 3rd, 2011, 4:54 pm

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

pedram_manowar
CJ Wannabe
CJ Wannabe
Posts: 4
Joined: September 27th, 2010, 6:56 am
Gamertag: +:|M.VIPER|:+â„¢
Contact:

Re: scripting help

Post by pedram_manowar » January 3rd, 2011, 5:45 pm

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?

Pedsdude
Site Admin
Site Admin
Posts: 15914
Joined: October 15th, 2004, 7:18 pm
Location: UK

Re: scripting help

Post by Pedsdude » January 3rd, 2011, 6:05 pm

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

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: scripting help

Post by F |Madness| U » January 3rd, 2011, 6:42 pm

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

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: scripting help

Post by IzNoGoD » January 4th, 2011, 1:06 am

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.
LMGTFY!

Its not a glitch... Its the future!

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests