Cods fail help
#1

today i made eject system for hunter and hydra but its not working

pawn Код:
if(newkeys == KEY_YES)
        {
        new vid = GetPlayerVehicleID(playerid);
        new Float:hp;
        GetVehicleHealth(vid, hp);
        if(vid == 425 && vid == 520 && hp < 251)
        {
            new Float:X, Float:Y, Float:Z;
            GetPlayerPos(playerid, X, Y, Z);
            SetPlayerPos(playerid, X, Y , Z + 40);
            SendClientMessage(playerid, RED, "Ejected!");
        }
    }
Reply
#2

Why are you checking for KEY_YES? That isn't called when a player enters a vehicle. Also, you should check out this page on the SA:MP wiki: https://sampwiki.blast.hk/wiki/OnPlayerK...heck_for_a_key

You can't check for keys that way.

If you want to eject people when they enter a car it's better to use OnPlayerStateChange and do something like this:

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
     if(newstate == PLAYER_STATE_DRIVER)
     {
      //your code
     }
     return 1;
}
Reply
#3

no no

look call back you will understand

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
When player press y He will eject player
Reply
#4

Well then you are checking for the key being pressed incorrectly.

Use this:

pawn Код:
// PRESSED(keys)
#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
Then change the line in your code from "if(newkeys == KEY_YES)" to "if(PRESSED(KEY_YES))"
Reply
#5

Код:
#define PRESSED(%0) \
	(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (PRESSED(KEY_YES))
    {
        new vid = GetPlayerVehicleID(playerid);
        new Float:hp;
        GetVehicleHealth(vid, hp);
        if(vid == 425 && vid == 520 && hp < 251)
        {
            new Float:X, Float:Y, Float:Z;
            GetPlayerPos(playerid, X, Y, Z);
            SetPlayerPos(playerid, X, Y , Z + 40);
            SendClientMessage(playerid, RED, "Ejected!");
        }
    }
	return 1;
}
Reply
#6

First, read the note on this page. Secondly, think about your logic. A vehicle's model can't be both 425 AND 520 at the same time.
Reply
#7

Quote:
Originally Posted by Thanos1997
Посмотреть сообщение
Код:
#define PRESSED(%0) \
	(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (PRESSED(KEY_YES))
    {
        new vid = GetPlayerVehicleID(playerid);
        new Float:hp;
        GetVehicleHealth(vid, hp);
        if(vid == 425 && vid == 520 && hp < 251)
        {
            new Float:X, Float:Y, Float:Z;
            GetPlayerPos(playerid, X, Y, Z);
            SetPlayerPos(playerid, X, Y , Z + 40);
            SendClientMessage(playerid, RED, "Ejected!");
        }
    }
	return 1;
}
Not working
Reply
#8

Firstly, look what Vince said.
You are checking if vehicle ID is 425 AND 520 (&&), and that's impossible.
You have to check if vehicle ID is 425 OR 520(||).

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if (PRESSED(KEY_YES))
{
new vid = GetPlayerVehicleID(playerid);
new Float:hp;
GetVehicleHealth(vid, hp);
if(vid == 425 || vid == 520 && hp < 251)
{
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
SetPlayerPos(playerid, X, Y , Z + 40);
SendClientMessage(playerid, RED, "Ejected!");
}
}
return 1;
}
Reply
#9

pawn Код:
if (PRESSED(KEY_YES))
    {
        new vid = GetPlayerVehicleID(playerid);
        new Float:hp;
        GetVehicleHealth(vid, hp);
        if(vid == 425 || vid == 520 && hp < 251)
        {
            new Float:X, Float:Y, Float:Z;
            GetPlayerPos(playerid, X, Y, Z);
            SetPlayerPos(playerid, X, Y , Z + 40);
            SendClientMessage(playerid, RED, "Ejected!");
        }
    }
    return 1;
}
STILL NOT WORKING
Reply
#10

What if you try it without hp?
if (PRESSED(KEY_YES))
{
new vid = GetPlayerVehicleID(playerid);
if(vid == 425 || vid == 520)
{
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
SetPlayerPos(playerid, X, Y , Z + 40);
SendClientMessage(playerid, RED, "Ejected!");
}
return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)