OnPlayerKeyStateChange.. -
CesarLT - 04.10.2013
Hello everyone, I am trying to get two keys to work, but I am having trouble with scripting the second key, as the first key works, but the second just doesn't respond in-game.
This function is new to me, and SAMP Wiki, didn't help..
Could you explain to me what I am doing wrong?
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(GetPlayerTeam(playerid) == 2)
{
if(Flaming[playerid] == 1)
{
if(newkeys & KEY_AIM)
{
new Float:PosX, Float: PosY, Float: PosZ;
GetPlayerPos(playerid, PosX, PosY, PosZ);
CreateExplosion(PosX, PosY, PosZ, 10, 10);
}
else { return 0; }
}
}
else if(newkeys & KEY_YES)
{
if(GetPlayerTeam(playerid) == 2)
{
if(Flaming[playerid] == 0)
{
Flaming[playerid] = 1;
SetPlayerAttachedObject( playerid, 0, 18693, 5, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 );
SetPlayerAttachedObject( playerid, 1, 18693, 6, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 );
SetPlayerAttachedObject( playerid, 2, 18703, 6, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 );
SetPlayerAttachedObject( playerid, 3, 18703, 5, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 );
SetPlayerWeather(playerid, 21);
SendClientMessage(playerid, COLOR_LIGHTBLUE, "[TEAM] {FFFFFF}- You're currently using {37FF00}superpowers{FFFFFF}, /superpowers to see the {FF8921}privileges{FFFFFF}.");
}
else if(Flaming[playerid] == 1)
{
Flaming[playerid] = 0;
for ( new i = 0; i < 4; i++ )
if ( IsPlayerAttachedObjectSlotUsed( playerid, i ) )
RemovePlayerAttachedObject( playerid, i );
SetPlayerWeather(playerid, 8);
}
}
else { SendClientMessage(playerid, COLOR_RED, "[TEAM] {FFFFFF}- You're not a {FF0000}zombie{FFFFFF}!"); return 1; }
}
Thanks in advance.
P.S. - If anyone could respond here please, that would be awsome.
Re: OnPlayerKeyStateChange.. -
Jankingston - 04.10.2013
try to change the 2nd key to KEY_NO
Re: OnPlayerKeyStateChange.. -
Dragonsaurus - 04.10.2013
Change "else if" to "if".
Re: OnPlayerKeyStateChange.. -
CesarLT - 04.10.2013
Quote:
Originally Posted by Jankingston
try to change the 2nd key to KEY_NO
|
Quote:
Originally Posted by Dragonsaurus
Change "else if" to "if".
|
Both didn't work...I don't know what's wrong..
Re: OnPlayerKeyStateChange.. -
Dragonsaurus - 04.10.2013
Which "else if" did you change?
Edit: Your code was messed up.
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(GetPlayerTeam(playerid) == 2)
{
if(newkeys & KEY_AIM)
{
if(Flaming[playerid] == 1)
{
new Float:PosX, Float: PosY, Float: PosZ;
GetPlayerPos(playerid, PosX, PosY, PosZ);
CreateExplosion(PosX, PosY, PosZ, 10, 10);
}
}
if(newkeys & KEY_YES)
{
if(Flaming[playerid] == 0)
{
Flaming[playerid] = 1;
SetPlayerAttachedObject( playerid, 0, 18693, 5, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 );
SetPlayerAttachedObject( playerid, 1, 18693, 6, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 );
SetPlayerAttachedObject( playerid, 2, 18703, 6, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 );
SetPlayerAttachedObject( playerid, 3, 18703, 5, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 );
SetPlayerWeather(playerid, 21);
SendClientMessage(playerid, COLOR_LIGHTBLUE, "[TEAM] {FFFFFF}- You're currently using {37FF00}superpowers{FFFFFF}, /superpowers to see the {FF8921}privileges{FFFFFF}.");
}
else if(Flaming[playerid] == 1)
{
Flaming[playerid] = 0;
for ( new i = 0; i < 4; i++ )
if ( IsPlayerAttachedObjectSlotUsed( playerid, i ) )
RemovePlayerAttachedObject( playerid, i );
SetPlayerWeather(playerid, 8);
}
}
}
else SendClientMessage(playerid, COLOR_RED, "[TEAM] {FFFFFF}- You're not a {FF0000}zombie{FFFFFF}!"); return 1;
}
Re: OnPlayerKeyStateChange.. -
CesarLT - 04.10.2013
Quote:
Originally Posted by Dragonsaurus
Which "else if" did you change?
Edit: Your code was messed up.
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) { if(GetPlayerTeam(playerid) == 2) { if(newkeys & KEY_AIM) { if(Flaming[playerid] == 1) { new Float:PosX, Float: PosY, Float: PosZ; GetPlayerPos(playerid, PosX, PosY, PosZ); CreateExplosion(PosX, PosY, PosZ, 10, 10); } } if(newkeys & KEY_YES) { if(Flaming[playerid] == 0) { Flaming[playerid] = 1; SetPlayerAttachedObject( playerid, 0, 18693, 5, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 ); SetPlayerAttachedObject( playerid, 1, 18693, 6, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 ); SetPlayerAttachedObject( playerid, 2, 18703, 6, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 ); SetPlayerAttachedObject( playerid, 3, 18703, 5, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 ); SetPlayerWeather(playerid, 21); SendClientMessage(playerid, COLOR_LIGHTBLUE, "[TEAM] {FFFFFF}- You're currently using {37FF00}superpowers{FFFFFF}, /superpowers to see the {FF8921}privileges{FFFFFF}."); } else if(Flaming[playerid] == 1) { Flaming[playerid] = 0; for ( new i = 0; i < 4; i++ ) if ( IsPlayerAttachedObjectSlotUsed( playerid, i ) ) RemovePlayerAttachedObject( playerid, i ); SetPlayerWeather(playerid, 8); } } } else SendClientMessage(playerid, COLOR_RED, "[TEAM] {FFFFFF}- You're not a {FF0000}zombie{FFFFFF}!"); return 1; }
|
That works..but there are two more problems, on the first login, I can still explode if I am not using powers, but after I turn them on (Y) and later off I can't explode anymore like it shall be. How can I deisable the login issue? And by the way, how can I return NOTHING, to the player who is not a zombie, (teamid 1), as he keeps getting those messages, "You're not a zombie", and it shall appear only when he's hitting the Y key, but it appears everytime he uses the aim button.
Thanks in advance.
Re: OnPlayerKeyStateChange.. -
Dragonsaurus - 04.10.2013
Can't really do anything the first part, but I can fix the messages issue.
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(GetPlayerTeam(playerid) == 2)
{
if(newkeys & KEY_AIM)
{
if(Flaming[playerid] == 1)
{
new Float:PosX, Float: PosY, Float: PosZ;
GetPlayerPos(playerid, PosX, PosY, PosZ);
CreateExplosion(PosX, PosY, PosZ, 10, 10);
}
}
if(newkeys & KEY_YES)
{
if(Flaming[playerid] == 0)
{
Flaming[playerid] = 1;
SetPlayerAttachedObject( playerid, 0, 18693, 5, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 );
SetPlayerAttachedObject( playerid, 1, 18693, 6, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 );
SetPlayerAttachedObject( playerid, 2, 18703, 6, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 );
SetPlayerAttachedObject( playerid, 3, 18703, 5, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 );
SetPlayerWeather(playerid, 21);
SendClientMessage(playerid, COLOR_LIGHTBLUE, "[TEAM] {FFFFFF}- You're currently using {37FF00}superpowers{FFFFFF}, /superpowers to see the {FF8921}privileges{FFFFFF}.");
}
else if(Flaming[playerid] == 1)
{
Flaming[playerid] = 0;
for ( new i = 0; i < 4; i++ )
if ( IsPlayerAttachedObjectSlotUsed( playerid, i ) )
RemovePlayerAttachedObject( playerid, i );
SetPlayerWeather(playerid, 8);
}
else SendClientMessage(playerid, COLOR_RED, "[TEAM] {FFFFFF}- You're not a {FF0000}zombie{FFFFFF}!");
}
}
return 1;
}
Re: OnPlayerKeyStateChange.. -
CesarLT - 04.10.2013
Quote:
Originally Posted by Dragonsaurus
Can't really do anything the first part, but I can fix the messages issue.
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) { if(GetPlayerTeam(playerid) == 2) { if(newkeys & KEY_AIM) { if(Flaming[playerid] == 1) { new Float:PosX, Float: PosY, Float: PosZ; GetPlayerPos(playerid, PosX, PosY, PosZ); CreateExplosion(PosX, PosY, PosZ, 10, 10); } } if(newkeys & KEY_YES) { if(Flaming[playerid] == 0) { Flaming[playerid] = 1; SetPlayerAttachedObject( playerid, 0, 18693, 5, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 ); SetPlayerAttachedObject( playerid, 1, 18693, 6, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 ); SetPlayerAttachedObject( playerid, 2, 18703, 6, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 ); SetPlayerAttachedObject( playerid, 3, 18703, 5, 1.983503, 1.558882, -0.129482, 86.705787, 308.978118, 268.198822, 1.500000, 1.500000, 1.500000 ); SetPlayerWeather(playerid, 21); SendClientMessage(playerid, COLOR_LIGHTBLUE, "[TEAM] {FFFFFF}- You're currently using {37FF00}superpowers{FFFFFF}, /superpowers to see the {FF8921}privileges{FFFFFF}."); } else if(Flaming[playerid] == 1) { Flaming[playerid] = 0; for ( new i = 0; i < 4; i++ ) if ( IsPlayerAttachedObjectSlotUsed( playerid, i ) ) RemovePlayerAttachedObject( playerid, i ); SetPlayerWeather(playerid, 8); } else SendClientMessage(playerid, COLOR_RED, "[TEAM] {FFFFFF}- You're not a {FF0000}zombie{FFFFFF}!"); } } return 1; }
|
Thanks, I've fixed the first problem on my own, I had Flaming == 1 onplayerconnect, lol.
Your message solution worked, ty.