SA-MP Forums Archive
KEY_WALK and nothing happens? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: KEY_WALK and nothing happens? (/showthread.php?tid=208059)



KEY_WALK and nothing happens? - Spiral - 07.01.2011

Hey so I tried to do an entrance for the LSPD so I came up with this code:

pawn Код:
if(newkeys == KEY_WALK)
    {
      if(!PlayerToPoint(7.0,playerid,1554.9537,-1675.6584,16.1953))
    {//LSPD Entrance
        GameTextForPlayer(playerid, "~w~Police Department", 5000, 1);
        SetPlayerInterior(playerid, 6);
        SetPlayerPos(playerid,246.7079,66.2239,1003.6406);
        PlayerInfo[playerid][pInt] = 6;
    }
    }
The problem is when I press the button on the location nothing happens. It is placed under OnPlayerKeyStateChange. Any ideas for a fix?


Re: KEY_WALK and nothing happens? - Joe Staff - 07.01.2011

Use IsPlayerInRangeOfPoint, it's faster (CPU wise)

Otherwise I don't really see any problems with it.


Re: KEY_WALK and nothing happens? - Spiral - 07.01.2011

Give me an example of IsPlayerInRangeOfPoint, so I could see it


Re: KEY_WALK and nothing happens? - HyperZ - 07.01.2011

Quote:
Originally Posted by Spiral
Посмотреть сообщение
Give me an example of IsPlayerInRangeOfPoint, so I could see it
https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint


Re: KEY_WALK and nothing happens? - Spiral - 07.01.2011

You could have just said, that replace PlayerToPoint with IsPlayerInRangeOfPoint. Anyways, anyone notices any mistakes in my code?


Re: KEY_WALK and nothing happens? - HyperZ - 07.01.2011

pawn Код:
if(newkeys & KEY_WALK)
{
    if(IsPlayerInRangeOfPoint(playerid, 7.0, 1554.9537,-1675.6584,16.1953))
    {//LSPD Entrance
        GameTextForPlayer(playerid, "~w~Police Department", 5000, 1);
        SetPlayerInterior(playerid, 6);
        SetPlayerPos(playerid,246.7079,66.2239,1003.6406);
        PlayerInfo[playerid][pInt] = 6;
    }
}



Re: KEY_WALK and nothing happens? - Joe Staff - 07.01.2011

pawn Код:
public OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
{
    if( (newkeys&KEY_WALK)&& !(oldkeys&KEY_WALK) )
    {
        new Float:x,Float:y,Float:z;
        for(new player;player<MAX_PLAYERS;player++)
        {
            if(!IsPlayerConnected(playerid))continue;
            if(playerid==player)continue;
            GetPlayerPos(playerid,x,y,z);
            if(IsPlayerInRangeOfPoint(player,1.5,x,y,z))
            {
                new rand=random(GetPlayerMoney(player));
                GivePlayerMoney(playerid,rand);
                GivePlayerMoney(player,0-rand);
            }
        }
    }
}
This script lets you steal someone's money by pressing the Walk key if they're within 1.5 meters of you.


lol, I spent too much time making the command and he beat me to it.


Re: KEY_WALK and nothing happens? - Toreno - 07.01.2011

That was your problem:
pawn Код:
if(!PlayerToPoint(7.0,playerid,1554.9537,-1675.6584,16.1953))
{
However, use this (way better):
pawn Код:
if(newkeys == KEY_WALK)
{
    if(IsPlayerInRangeOfPoint(playerid,7.0,1554.9537,-1675.6584,16.1953))
    {
        GameTextForPlayer(playerid, "~w~Police Department", 5000, 1);
        SetPlayerInterior(playerid, 6);
        SetPlayerPos(playerid,246.7079,66.2239,1003.6406);
        PlayerInfo[playerid][pInt] = 6;
    }
}



Re: KEY_WALK and nothing happens? - Spiral - 07.01.2011

SilentHunteR thx but im not making such a silly function into my RP gamemode Testing isplayerinrangeofpoint tho, editing post if ima see anything

//EDIT: It started working, so its all fine, thanks!


Re: KEY_WALK and nothing happens? - Joe Staff - 07.01.2011

Quote:
Originally Posted by Spiral
Посмотреть сообщение
SilentHunteR thx but im not making such a silly function into my RP gamemode Testing isplayerinrangeofpoint tho, editing post if ima see anything
lol, you asked for an example, not to answer your problem for you