KEY_WALK and nothing happens?
#1

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?
Reply
#2

Use IsPlayerInRangeOfPoint, it's faster (CPU wise)

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

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

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

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

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;
    }
}
Reply
#7

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.
Reply
#8

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;
    }
}
Reply
#9

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!
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)