SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 25/01/2020, 01:13 PM   #1
Xored
Little Clucker
 
Join Date: Jul 2017
Posts: 15
Reputation: 3
Default Can't press enter to enter in a building

I try to make a system where when you press the "enter" key in a certain area you will be teleported inside. I made the code, but something is not right, because when I press enter at that location, nothing happens.
Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if(IsPlayerInRangeOfPoint(playerid, 10, 1219.9609,-1811.9579,16.5938))
	{
		if(newkeys == KEY_SECONDARY_ATTACK)
		{
    		if(GetPlayerInterior(playerid)==0 && GetPlayerVirtualWorld(playerid)==0)
    		{
         		SetPlayerInterior(playerid,3);
         		SetPlayerPos(playerid, 1494.325195,1304.942871,1093.289062);
    		}
		}
	}
	return 1;
}
Xored is offline   Reply With Quote
Old 25/01/2020, 01:21 PM   #2
SiaReyes
Gangsta
 
Join Date: Mar 2019
Location: Coordinates X,Y,Z
Posts: 618
Reputation: 57
Default Re: Can't press enter to enter in a building

pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_SECONDARY_ATTACK)
    {
        if(IsPlayerInRangeOfPoint(playerid, 2.5, 1219.9609,-1811.9579, 16.5938))
        {
                if(GetPlayerInterior(playerid) == 0 && GetPlayerVirtualWorld(playerid)== 0)
                {
                    SetPlayerInterior(playerid, 3);
                    SetPlayerPos(playerid, 1494.325195,1304.942871,1093.289062);
                }
        }
    }
    return 1;
}

if this doesn't work, check the coordinates are right.
SiaReyes is offline   Reply With Quote
Old 25/01/2020, 01:28 PM   #3
Xored
Little Clucker
 
Join Date: Jul 2017
Posts: 15
Reputation: 3
Default Re: Can't press enter to enter in a building

Thanks,that worked!
Xored is offline   Reply With Quote
Old 25/01/2020, 02:07 PM   #4
Markski
Big Clucker
 
Markski's Avatar
 
Join Date: Apr 2015
Location: La Plata, Argentina
Posts: 133
Reputation: 59
Default Re: Can't press enter to enter in a building

For future reference, keep in mind using "&" instead of "==" is ideal for key state. This is because & functions as a bit-wise "and", meaning it'll check for that key being pressed instead of checking for that key being the only one pressed (since, despite it's name, newkeys is misleadingly composed by all the keys being pressed at once, not just the new key)
Markski is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to enter the building or door by pressing the enter key kurniarocki Scripting Help 6 08/04/2014 05:43 AM
How to create "Press F to enter the building" Nostrum Scripting Help 6 01/05/2013 07:41 PM
Key press enter building Stephanz Scripting Help 3 27/03/2012 12:26 PM
Press "enter" to /enter a building. .:*Starstrike*:. Help Archive 8 02/08/2010 01:24 AM
how to make like if you press "F" or enter then enters building? hardstop Help Archive 3 28/04/2010 11:18 AM


All times are GMT. The time now is 09:26 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.