Can't press enter to enter in a building - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Can't press enter to enter in a building (
/showthread.php?tid=672053)
Can't press enter to enter in a building -
Xored - 25.01.2020
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;
}
Re: Can't press enter to enter in a building -
SiaReyes - 25.01.2020
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.
Re: Can't press enter to enter in a building -
Xored - 25.01.2020
Thanks,that worked!
Re: Can't press enter to enter in a building -
Markski - 25.01.2020
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)