29.06.2012, 16:13
I get these errors in my console from time to time
Can someone tell me what is the problem? Here's my OnPlayerKeyState code
Код:
[18:22:39] [debug] #0 0012d438 in OnPlayerKeyStateChange () from csrp.amx [18:22:39] [debug] Backtrace (most recent call first): [18:22:39] [debug] Accessing element at index 255 past array upper bound 9 [18:22:39] [debug] Run time error 4: "Array index out of bounds" [18:22:38] [debug] #0 0012d438 in OnPlayerKeyStateChange () from csrp.amx [18:22:38] [debug] Backtrace (most recent call first): [18:22:38] [debug] Accessing element at index 255 past array upper bound 9 [18:22:38] [debug] Run time error 4: "Array index out of bounds"
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(PRESSED(KEY_SUBMISSION))
{
if(IsPlayerUsingRopes[playerid] == true)
{
TogglePlayerControllable(playerid, 0);
IsPlayerUsingRopes[playerid] = false;
SetTimerEx("UnfreezePlayer", 1000, false, "i", playerid);
return 1;
}
if(IsPlayerInAnyVehicle(playerid) && UsingRopes == true && GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
{
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 497)
{
new vid = GetPlayerVehicleID(playerid);
for(new ply=0;ply<MAX_PLAYERS;ply++) // check if seat id 3 is taken
{
if(ply != playerid)
{
if(GetPlayerVehicleSeat(ply) == 3) return SendClientMessage(playerid, COLOR_ORANGE, "[ERROR:] Wait for the first person to rope down ((seat ID 3)).");
}
}
IsPlayerUsingRopes[playerid] = true;
RemovePlayerFromVehicle(playerid);
PutPlayerInVehicle(playerid, vid, 3);
new Float:x11[3];
GetPlayerPos(playerid, x11[0], x11[1], x11[2]);
new Float:carzangle;
GetVehicleZAngle(vid, carzangle);
RemovePlayerFromVehicle(playerid);
SetPlayerPos(playerid, x11[0],x11[1],x11[2] - 0.8);
SetPlayerFacingAngle(playerid, carzangle - 90);
GetXYBehindPlayer(playerid, x11[0], x11[1], 0.55);
SetPlayerPos(playerid, x11[0],x11[1],x11[2] - 0.8);
SetPlayerFacingAngle(playerid, carzangle - 90);
ApplyAnimation(playerid,"ped","abseil",4.0,0,0,0,1,0);
GetPlayerHealth(playerid, oldhp[playerid]);
SetPlayerHealth(playerid, 1000);
SetTimerEx("UnfreezePlayer", 2000, false, "i", playerid);
return 1;
}
}
}
if(newkeys & KEY_JUMP && !(oldkeys & KEY_JUMP) && GetPlayerSpecialAction(playerid) == 24) ApplyAnimation(playerid, "GYMNASIUM", "gym_jog_falloff",4.1,0,1,1,0,0);
if(PRESSED(KEY_ACTION) || HOLDING(KEY_ACTION) || RELEASED(KEY_ACTION))
{
if(IsPlayerInAnyVehicle(playerid))
{
if(IsPlayerInBaron[playerid] == 1)
{
IsPlayerInBaron[playerid] = 0;
SetPlayerPos(playerid, RCPos[playerid][0], RCPos[playerid][1], RCPos[playerid][2]);
return SendClientMessage(playerid, COLOR_ORANGE, "[WARNING:] RC Baron's minigun is disabled, don't use it.");
}
}
}
if(PRESSED(KEY_SUBMISSION) && (GetPlayerVehicleID(playerid) == PDCar[11] || GetPlayerVehicleID(playerid) == PDCar[14]) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
if(GetPlayerVehicleID(playerid) == PDCar[11])
{
if(eLightsOn[0])
{
DestroyObject(EmergencyLightsObject[0]);
EmergencyLightsObject[0] = CreateObject(19420, 0,0,0,0,0,0,300);
AttachObjectToVehicle(EmergencyLightsObject[0], PDCar[11], 0.009999, -1.844998, 0.234999, 0.000000, 0.000000, 0.000000); //Object Model: 19419 |
eLightsOn[0] = false;
return 1;
}
eLightsOn[0] = true;
DestroyObject(EmergencyLightsObject[0]);
EmergencyLightsObject[0] = CreateObject(19419, 0,0,0,0,0,0,300);
AttachObjectToVehicle(EmergencyLightsObject[0], PDCar[11], 0.009999, -1.844998, 0.234999, 0.000000, 0.000000, 0.000000); //Object Model: 19419 |
return 1;
}
if(GetPlayerVehicleID(playerid) == PDCar[14])
{
if(eLightsOn[1])
{
DestroyObject(EmergencyLightsObject[1]);
EmergencyLightsObject[1] = CreateObject(19420, 0,0,0,0,0,0,300);
AttachObjectToVehicle(EmergencyLightsObject[1], PDCar[14], 0.000000, 0.000000, 1.054999, 0.000000, 0.000000, 0.000000); //Object Model: 19419 |
eLightsOn[1] = false;
return 1;
}
eLightsOn[1] = true;
DestroyObject(EmergencyLightsObject[1]);
EmergencyLightsObject[1] = CreateObject(19419, 0,0,0,0,0,0,300);
AttachObjectToVehicle(EmergencyLightsObject[1], PDCar[14], 0.000000, 0.000000, 1.054999, 0.000000, 0.000000, 0.000000); //Object Model: 19419 |
return 1;
}
}
if(PRESSED(KEY_FIRE))
{
if(GetPlayerSpecialAction(playerid) == 21 && IsPlayerUsingWeed[playerid])
{
if(WeedSpam[playerid] != 0) return SendClientMessage(playerid, COLOR_ORANGE, "[ERROR:] You need to wait 5 seconds before each puff.");
if(WeedPuffs[playerid] > 0)
{
WeedPuffs[playerid] -= 1;
SetPlayerDrunkLevel(playerid, GetPlayerDrunkLevel(playerid) + 1500);
PlayerActionMessage(playerid, 12, "takes a puff from his blunt.");
new Float:hp;
GetPlayerHealth(playerid, hp);
SetPlayerHealth(playerid, hp+1);
SetTimerEx("AntiSpam", 5000, false, "i", playerid);
return 1;
}
else
{
PlayerActionMessage(playerid, 12, "throws his blunt on the ground.");
WeedPuffs[playerid] = 0;
SetPlayerSpecialAction(playerid, 0);
IsPlayerUsingWeed[playerid] = false;
return 1;
}
}
}
if(PRESSED(KEY_FIRE))
{
if((CopOnDuty[playerid] == 1 || EMSOnDuty[playerid] == 1 || DynamicFactions[PlayerInfo[playerid][pFaction]][fType] == 2) && GetPlayerWeapon(playerid) == 23 && Tazer[playerid] == 1)
{
new Float:X,Float:Y,Float:Z,Float:pX,Float:pY,Float:pZ;
GetPlayerPos(playerid, pX,pY,pZ);
for(new i=0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(IsPlayerInRangeOfPoint(i,20, pX,pY,pZ))
{
if(i != playerid)
{
GetPlayerPos(i, X,Y,Z);
if(IsPlayerAimingAtPlayer(playerid, i))
{
SetPlayerDrunkLevel(i, 3000);
GameTextForPlayer(i,"~r~Tazed",1000,4);
Tazed[i] = 1;
TogglePlayerControllable(i, 0);
ApplyAnimation(i, "CRACK", "crckdeth2", 4.0, 1, 0, 0, 0, 0, 1);
SetTimerEx("StopAnimationEx",20000,false,"i",i);
new string[128];
format(string, sizeof(string),"aims his Tazer at %s and shoots it.",GetPlayerNameEx(i));
PlayerActionMessage(playerid,20.0,string);
}
}
}
}
}
}
}
if(PRESSED(KEY_FIRE))
{
if((CopOnDuty[playerid] == 1 || DynamicFactions[PlayerInfo[playerid][pFaction]][fType] == 2))
{
if(GetPlayerWeapon(playerid) == 39) // check if they have C4
{
for(new hi = 0; hi < sizeof(Houses); hi++)
{
if (PlayerToPoint(3.0, playerid,Houses[hi][EnterX], Houses[hi][EnterY], Houses[hi][EnterZ]) || PlayerToPoint(3.0, playerid,Houses[hi][ExitX], Houses[hi][ExitY], Houses[hi][ExitZ]))
{
PlayerActionMessage(playerid, 12, "places a C4 charge on the door.");
DoorToBlast[playerid][0] = hi;
HasDetonator[playerid] = true;
return 1;
}
}
for(new bi = 0; bi < sizeof(Businesses); bi++)
{
if (PlayerToPoint(3.0, playerid,Businesses[bi][EnterX], Businesses[bi][EnterY], Businesses[bi][EnterZ]) || PlayerToPoint(3.0, playerid,Businesses[bi][ExitX], Businesses[bi][ExitY], Businesses[bi][ExitZ]))
{
PlayerActionMessage(playerid, 12, "places a C4 charge on the door.");
DoorToBlast[playerid][1] = bi;
HasDetonator[playerid] = true;
return 1;
}
}
return 1;
}
if(HasDetonator[playerid] == true) // check if they have detonator
{
HasDetonator[playerid] = false;
if(DoorToBlast[playerid][0] != -1)
{
Houses[DoorToBlast[playerid][0]][Locked] = 0;
CreateExplosion(Houses[DoorToBlast[playerid][0]][EnterX], Houses[DoorToBlast[playerid][0]][EnterY], Houses[DoorToBlast[playerid][0]][EnterZ], 12, 5);
DoorToBlast[playerid][0] = -1;
PlayerActionMessage(playerid, 12, "detonates the C4 charge and blows the door open.");
SetPlayerArmedWeapon(playerid, 0);
return 1;
}
if(DoorToBlast[playerid][1] != -1)
{
Businesses[DoorToBlast[playerid][1]][Locked] = 0;
CreateExplosion(Businesses[DoorToBlast[playerid][1]][EnterX], Businesses[DoorToBlast[playerid][1]][EnterY], Businesses[DoorToBlast[playerid][1]][EnterZ], 12, 5);
DoorToBlast[playerid][1] = -1;
SetPlayerArmedWeapon(playerid, 0);
PlayerActionMessage(playerid, 12, "detonates the C4 charge and blows the door open.");
return 1;
}
return 1;
}
}
}
if(newkeys & 16) // Is the 'key value' of the enter vehicle control.new Float:x,Float:y,Float:z; Scroll down for more information about this '&'
{
new Float:x, Float:y, Float:z;
if(IsPlayerInAnyVehicle(playerid) && IsVehicleRCVehicle(GetPlayerVehicleID(playerid))) // Checks if the player is in a vehicle and, if so, if the vehicle is a RC vehicle.
{
SetPlayerPos(playerid,RCPos[playerid][0],RCPos[playerid][1],RCPos[playerid][2]);
IsPlayerInBaron[playerid] = 0;
return 1; // OnPlayerKeyStateChange won't be executed any further.
}
for(new v; v < MAX_VEHICLES; v++) // Loop through all vehicles
{
GetVehiclePos(v,x,y,z);
if(IsPlayerInRangeOfPoint(playerid,4,x,y,z) && IsVehicleRCVehicle(v)) //Check if the player is near a RC vehicle.
{
if(v != RCToy[playerid] && PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_ORANGE, "[ERROR:] You can't control this toy.");
if(GetVehicleModel(v) == 464) IsPlayerInBaron[playerid] = 1;
GetPlayerPos(playerid, RCPos[playerid][0],RCPos[playerid][1],RCPos[playerid][2]);
PutPlayerInVehicle(playerid,v,0); // Put the player in the RC vehicle
return 1; // OnPlayerKeyStateChange won't be executed any further.
}
}
}
if ((newkeys & (KEY_JUMP | KEY_SPRINT)) == (KEY_JUMP | KEY_SPRINT) && (oldkeys & (KEY_JUMP | KEY_SPRINT)) != (KEY_JUMP | KEY_SPRINT))
{
if(IsPlayerConnected (playerid))
{
new string[128];
if(PlayerInfo[playerid][pRace] == 2)
{
if(VampireAbility[playerid][vJump] > 0)
{
if(!IsPlayerInAnyVehicle(playerid))
{
if(Drugged[playerid] == 0)
{
if(!UsedCommandVampireJump[playerid])
{
UsedCommandVampireJump[playerid] = 1;
SetTimerEx("VampireJumpCoolDown", (8-VampireAbility[playerid][vJump])*1000, false, "i", playerid);
new Float:vx, Float:vy, Float:vz;
new Float:rot;
GetPlayerFacingAngle(playerid, rot);
rot = 360 - rot;
GetPlayerVelocity(playerid,vx,vy,vz);
SetPlayerVelocity(playerid,vx+(VampireAbility[playerid][vJump]*0.02)*floatsin(rot, degrees),vy+(VampireAbility[playerid][vJump]*0.02)*floatcos(rot,degrees),vz+(VampireAbility[playerid][vJump]*0.1));
}
else
{
format(string, sizeof(string), "[ERROR:] You must wait %d seconds between each used /vampirejump.", 8-VampireAbility[playerid][vJump]);
SendClientMessage(playerid,COLOR_ORANGE,string);
}
}
else
{
SendClientMessage(playerid,COLOR_ORANGE,"[ERROR:] You feel weak, you have temporary lost your vampire abilities due to drug effect.");
}
}
}
}
}
return 1;
}
if(PRESSED(KEY_SECONDARY_ATTACK) || HOLDING(KEY_SECONDARY_ATTACK) || RELEASED(KEY_SECONDARY_ATTACK))
{
if(GetPlayerFightingStyle(playerid) == FIGHT_STYLE_KUNGFU)//Check if they using Kungfu fighting syle.
{
for(new i = 0; i < MAX_ONLINE_PLAYERS; i++)// Perform a loop to see who's playing anim
{
if(i != playerid)
{
new Float: DamagePos[3];
GetPlayerPos(playerid, DamagePos[0], DamagePos[1], DamagePos[2]);
if(IsPlayerInRangeOfPoint( i, 3, DamagePos[0], DamagePos[1], DamagePos[2]))
{
if(GetPlayerAnimationIndex(i) == 491 || GetPlayerAnimationIndex(i) == 492 || GetPlayerAnimationIndex(i) == 493 || GetPlayerAnimationIndex(i) == 1174 || GetPlayerAnimationIndex(i) == 1177 || GetPlayerAnimationIndex(i) == 1178 || GetPlayerAnimationIndex(i) == 1175)
{
new Float: CurrentHealth; // Variable for storing the looping players health to subtract from
GetPlayerHealth(i, CurrentHealth); // Get the players current health.
SetPlayerHealth(i, CurrentHealth-(VampireAbility[playerid][vComb]*4)); // Subtract 20
}
}
}
}
}
if(GetPlayerFightingStyle(playerid) == FIGHT_STYLE_BOXING)//Check if they using Boxing fighting syle.
{
for(new i = 0; i < MAX_ONLINE_PLAYERS; i++)// Perform a loop to see who's playing anim
{
if(i != playerid)
{
new Float: DamagePos[3];
GetPlayerPos(playerid, DamagePos[0], DamagePos[1], DamagePos[2]);
if(IsPlayerInRangeOfPoint( i, 3, DamagePos[0], DamagePos[1], DamagePos[2]))
{
if(GetPlayerAnimationIndex(i) == 479 || GetPlayerAnimationIndex(i) == 480 || GetPlayerAnimationIndex(i) == 481 || GetPlayerAnimationIndex(i) == 1174 || GetPlayerAnimationIndex(i) == 1177 || GetPlayerAnimationIndex(i) == 1178 || GetPlayerAnimationIndex(i) == 1175)
{
new Float: CurrentHealth; // Variable for storing the looping players health to subtract from
GetPlayerHealth(i, CurrentHealth); // Get the players current health.
SetPlayerHealth(i, CurrentHealth-(VampireAbility[playerid][vComb]*2)); // Subtract X
}
}
}
}
}
return 1;
}
if(PRESSED(KEY_SUBMISSION) && IsPlayerInAnyVehicle(playerid) && GetVehicleModel(GetPlayerVehicleID(playerid)) == 497 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new vid = GetPlayerVehicleID(playerid);
if(!UsingRopes)
{
UsingRopes = true;
AttachObjectToVehicle(HeliRopes[0], vid, 0.804999, 0.000000, -0.384999, 0.000000, 0.000000, 0.000000); //Object Model: 19087 |
AttachObjectToVehicle(HeliRopes[1], vid, 0.804999, 0.000000, -2.850017, 0.000000, 0.000000, 0.000000); //Object Model: 19087 |
AttachObjectToVehicle(HeliRopes[2], vid, 0.804999, 0.000000, -5.255072, 0.000000, 0.000000, 0.000000); //Object Model: 19087 |
AttachObjectToVehicle(HeliRopes[3], vid, 0.804999, 0.000000, -7.665127, 0.000000, 0.000000, 0.000000); //Object Model: 19087 |
AttachObjectToVehicle(HeliRopes[4], vid, 0.804999, 0.000000, -10.07, 0.000000, 0.000000, 0.000000); //Object Model: 19087 |
AttachObjectToVehicle(HeliRopes[5], vid, 0.804999, 0.000000, -12.40, 0.000000, 0.000000, 0.000000); //Object Model: 19087 |
RopesTimer = SetTimerEx("SetHeliPos", 100, true, "i", playerid);
GetVehiclePos(GetPlayerVehicleID(playerid), HeliPos[0], HeliPos[1], HeliPos[2]);
GetVehicleZAngle(GetPlayerVehicleID(playerid), HeliPos[3]);
ProxDetector(20.0, playerid, "* Ropes got released down from the helicopter." ,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
return 1;
}
DestroyObject(HeliRopes[0]);
DestroyObject(HeliRopes[1]);
DestroyObject(HeliRopes[2]);
DestroyObject(HeliRopes[3]);
DestroyObject(HeliRopes[4]);
DestroyObject(HeliRopes[5]);
HeliRopes[0] = CreateObject(19087 , 0,0,0,0,0,0,300);
HeliRopes[1] = CreateObject(19087 , 0,0,0,0,0,0,300);
HeliRopes[2] = CreateObject(19087 , 0,0,0,0,0,0,300);
HeliRopes[3] = CreateObject(19087 , 0,0,0,0,0,0,300);
HeliRopes[4] = CreateObject(19087 , 0,0,0,0,0,0,300);
HeliRopes[5] = CreateObject(19087 , 0,0,0,0,0,0,300);
UsingRopes = false;
KillTimer(RopesTimer);
ProxDetector(20.0, playerid, "* Ropes got detached from the helicopter." ,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
return 1;
}
if(PRESSED(KEY_FIRE) || HOLDING(KEY_FIRE) || RELEASED(KEY_FIRE))// Check if they pressed KEY_FIRE
{
if(GetPlayerWeapon(playerid) == 4) // Check if they have a knife
{
new Float: CurrentHealth; // Variable for storing the looping players health to subtract from
for(new i = 0; i < MAX_ONLINE_PLAYERS; i++)// Perform a loop to see who's playing anim
{
if(i != playerid)
{
new Float: DamagePos[3];
GetPlayerPos(playerid, DamagePos[0], DamagePos[1], DamagePos[2]);
if(IsPlayerInRangeOfPoint( i, 1, DamagePos[0], DamagePos[1], DamagePos[2]))
{
if(GetPlayerAnimationIndex(i) == 755 || GetPlayerAnimationIndex(i) == 756 || GetPlayerAnimationIndex(i) == 757 || GetPlayerAnimationIndex(i) == 1174 || GetPlayerAnimationIndex(i) == 1177 || GetPlayerAnimationIndex(i) == 1178 || GetPlayerAnimationIndex(i) == 1175)//KNIFE_KNIFE_HIT_1, KNIFE_KNIFE_HIT_2, KNIFE_KNIFE_HIT_3, PED_HIT_BEHIND, PED_HIT_L, PED_HIT_R, PED_HIT_FRONT
{
GetPlayerHealth(i, CurrentHealth); // Get the players current health.
SetPlayerHealth(i, CurrentHealth-(VampireAbility[playerid][vComb]*3)); // Subtract X
return 1;
}
}
}
}
}
if(GetPlayerWeapon(playerid) == 8) // Check if they have a katana
{
for(new i = 0; i < MAX_ONLINE_PLAYERS; i++)// Perform a loop to see who's playing anim
{
if(i != playerid)
{
new Float: DamagePos[3];
GetPlayerPos(playerid, DamagePos[0], DamagePos[1], DamagePos[2]);
if(IsPlayerInRangeOfPoint( i, 1, DamagePos[0], DamagePos[1], DamagePos[2]))
{
if(GetPlayerAnimationIndex(i) == 1550 || GetPlayerAnimationIndex(i) == 1551 || GetPlayerAnimationIndex(i) == 1553 || GetPlayerAnimationIndex(i) == 1174 || GetPlayerAnimationIndex(i) == 1177 || GetPlayerAnimationIndex(i) == 1178 || GetPlayerAnimationIndex(i) == 1175)//SWORD_SWORD_HIT_1, SWORD_SWORD_HIT_2, SWORD_SWORD_HIT_3, PED_HIT_BEHIND, PED_HIT_L, PED_HIT_R, PED_HIT_FRONT
{
new Float: CurrentHealth; // Variable for storing the looping players health to subtract from
GetPlayerHealth(i, CurrentHealth); // Get the players current health.
SetPlayerHealth(i, CurrentHealth-(VampireAbility[playerid][vComb]*6)); // Subtract X
return 1;
}
}
}
}
}
}
return 1;
}