Cods fail help -
Ryz - 13.10.2014
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!");
}
}
Re: Cods fail help -
Chenko - 13.10.2014
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;
}
Re: Cods fail help -
Ryz - 13.10.2014
no no
look call back you will understand
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
When player press y He will eject player
Re: Cods fail help -
Chenko - 13.10.2014
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))"
Re: Cods fail help -
Thanos1997 - 13.10.2014
Код:
#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;
}
Re: Cods fail help -
Vince - 13.10.2014
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.
Re: Cods fail help -
Ryz - 14.10.2014
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
Re: Cods fail help -
zaibaslr2 - 14.10.2014
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;
}
Re: Cods fail help -
Ryz - 14.10.2014
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
Re: Cods fail help -
zaibaslr2 - 14.10.2014
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;
}