15.01.2014, 22:51
(
Последний раз редактировалось nmader; 16.01.2014 в 02:20.
)
Hey there guys,
I have encountered a very serious situation that leaves me completely clueless after over seven hours of trying to fix this situation. My situation is that when a player enters a player-owned vehicle they cannot start the engine due to there being no fuel, even though there should be 100% fuel. After further investigating I found that the variables were loading successfully; however would reset for some reason?
I had it print a message when a player vehicle spawned, stating the ID (of the player spawned vehicle) and it gave the correct value, I then put it under a command (CMD:engine) and it stated that the ID was an incorrect value (0), which made the server read it as a faction vehicle or admin spawned vehicle.
I will seriously appreciate anyone who can aid me in finding the solution and I will be more than happy to provide reputation. The code involving the player ownership is below. I really need to fix this soon, as my custom gamemode is stuck until I can manage to fix this system, I have many people waiting on me to finish the script, and I can afford no delays.
Kind Regards & Best Wishes,
Nmader
Fellow Scripter
I have encountered a very serious situation that leaves me completely clueless after over seven hours of trying to fix this situation. My situation is that when a player enters a player-owned vehicle they cannot start the engine due to there being no fuel, even though there should be 100% fuel. After further investigating I found that the variables were loading successfully; however would reset for some reason?
I had it print a message when a player vehicle spawned, stating the ID (of the player spawned vehicle) and it gave the correct value, I then put it under a command (CMD:engine) and it stated that the ID was an incorrect value (0), which made the server read it as a faction vehicle or admin spawned vehicle.
I will seriously appreciate anyone who can aid me in finding the solution and I will be more than happy to provide reputation. The code involving the player ownership is below. I really need to fix this soon, as my custom gamemode is stuck until I can manage to fix this system, I have many people waiting on me to finish the script, and I can afford no delays.
pawn Код:
enum playerVehicleInfo
{
Float: playerVehiclePosition[3],
Float: playerVehicleRotation,
Float: playerVehicleGas,
playerVehicleModel,
playerVehicleID,
playerVehicleColor1,
playerVehicleColor2,
playerVehicleLocked,
playerTrunkArmour,
playerTrunkMoney,
playerTrunkWeapon1,
playerTrunkWeapon2,
playerTrunkWeapon3,
playerTrunkAmmo1,
playerTrunkAmmo2,
playerTrunkAmmo3,
playerTrunkPot,
playerTrunkCocaine,
playerTrunkMedicalKit,
playerTrunkMaterials,
playerOwnerID,
LicensePlate[8],
playerPlateRespawn,
playerVehicleSlot,
}
new pvInfo[MAX_VEHICLES][playerVehicleInfo];
pawn Код:
public OnPlayerSpawn(playerid)
{
initiatePlayerVehicles(playerid);
return 1;
}
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
DestroyVehicle(pVehicle1[playerid]);
DestroyVehicle(pVehicle2[playerid]);
DestroyVehicle(pVehicle3[playerid]);
return 1;
}
pawn Код:
forward initiatePlayerVehicles(playerid);
public initiatePlayerVehicles(playerid)
{
format(globalstring, sizeof(globalstring), "SELECT * FROM playervehicles WHERE playerOwnerID = '%d'", pInfo[playerid][pID]);
mysql_query(globalstring);
mysql_store_result();
new x;
while(mysql_retrieve_row())
{
mysql_get_field("playerOwnedVehicleID", result);
x = strval(result);
mysql_get_field("playerVehicleSlot", result);
pvInfo[x][playerVehicleSlot] = strval(result);
mysql_get_field("playerVehicleModel", result);
pvInfo[x][playerVehicleModel] = strval(result);
mysql_get_field("playerVehicleColor1", result);
pvInfo[x][playerVehicleColor1] = strval(result);
mysql_get_field("playerVehicleColor2", result);
pvInfo[x][playerVehicleColor2] = strval(result);
mysql_get_field("playerVehicleX", result);
pvInfo[x][playerVehiclePosition][0] = floatstr(result);
mysql_get_field("playerVehicleY", result);
pvInfo[x][playerVehiclePosition][1] = floatstr(result);
mysql_get_field("playerVehicleZ", result);
pvInfo[x][playerVehiclePosition][2] = floatstr(result);
mysql_get_field("playerVehicleRot", result);
pvInfo[x][playerVehicleRotation] = floatstr(result);
mysql_get_field("playerVehicleGas", result);
pvInfo[x][playerVehicleGas] = floatstr(result);
mysql_get_field("playerVehicleLocked", result);
pvInfo[x][playerVehicleLocked] = strval(result);
mysql_get_field("playerTrunkArmour", result);
pvInfo[x][playerTrunkArmour] = strval(result);
mysql_get_field("playerTrunkCash", result);
pvInfo[x][playerTrunkMoney] = strval(result);
mysql_get_field("playerTrunkWeapon1", result);
pvInfo[x][playerTrunkWeapon1] = strval(result);
mysql_get_field("playerTrunkWeapon2", result);
pvInfo[x][playerTrunkWeapon2] = strval(result);
mysql_get_field("playerTrunkWeapon3", result);
pvInfo[x][playerTrunkWeapon3] = strval(result);
mysql_get_field("playerTrunkAmmo1", result);
pvInfo[x][playerTrunkAmmo1] = strval(result);
mysql_get_field("playerTrunkAmmo2", result);
pvInfo[x][playerTrunkAmmo2] = strval(result);
mysql_get_field("playerTrunkAmmo3", result);
pvInfo[x][playerTrunkAmmo3]= strval(result);
mysql_get_field("playerTrunkPot", result);
pvInfo[x][playerTrunkPot] = strval(result);
mysql_get_field("playerTrunkCocaine", result);
pvInfo[x][playerTrunkCocaine] = strval(result);
mysql_get_field("playerTrunkMedicalKit", result);
pvInfo[x][playerTrunkMedicalKit] = strval(result);
mysql_get_field("playerTrunkMaterials", result);
pvInfo[x][playerTrunkMaterials] = strval(result);
mysql_get_field("playerOwnerID", result);
pvInfo[x][playerOwnerID] = strval(result);
if(!IsValidVehicle(pVehicle1[playerid]) || !IsValidVehicle(pVehicle2[playerid]) || !IsValidVehicle(pVehicle3[playerid]))
{
if(pvInfo[x][playerVehicleSlot] == 1)
{
if(!IsValidVehicle(pVehicle1[playerid]))
{
pVehicle1[playerid] = CreateVehicle(pvInfo[x][playerVehicleModel], pvInfo[x][playerVehiclePosition][0], pvInfo[x][playerVehiclePosition][1], pvInfo[x][playerVehiclePosition][2], pvInfo[x][playerVehicleRotation], pvInfo[x][playerVehicleColor1], pvInfo[x][playerVehicleColor2], 60000);
print("Vehicle one spawned for player!");
printf("Vehicle Slot: %d", pvInfo[x][playerVehicleSlot]);
SetVehicleToRespawn(pVehicle1[playerid]);
}
}
if(pvInfo[x][playerVehicleSlot] == 2)
{
if(!IsValidVehicle(pVehicle2[playerid]))
{
pVehicle2[playerid] = CreateVehicle(pvInfo[x][playerVehicleModel], pvInfo[x][playerVehiclePosition][0], pvInfo[x][playerVehiclePosition][1], pvInfo[x][playerVehiclePosition][2], pvInfo[x][playerVehicleRotation], pvInfo[x][playerVehicleColor1], pvInfo[x][playerVehicleColor2], 60000);
print("Vehicle two spawned for player!");
}
}
if(pvInfo[x][playerVehicleSlot] == 3)
{
if(!IsValidVehicle(pVehicle3[playerid]))
{
pVehicle3[playerid] = CreateVehicle(pvInfo[x][playerVehicleModel], pvInfo[x][playerVehiclePosition][0], pvInfo[x][playerVehiclePosition][1], pvInfo[x][playerVehiclePosition][2], pvInfo[x][playerVehicleRotation], pvInfo[x][playerVehicleColor1], pvInfo[x][playerVehicleColor2], 60000);
print("Vehicle three spawned for player!");
}
}
if(pvInfo[x][playerVehicleLocked] == 1)
{
SetVehicleParamsEx(x, engine, lights, alarm, 1, bonnet, boot, objective);
}
}
}
mysql_free_result();
return 1;
}
pawn Код:
CMD:engine(playerid,params[])
{
new vehicleid = GetPlayerVehicleID(playerid);
new model = GetVehicleModel(vehicleid);
GetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective);
if(!IsPlayerDriver(playerid)) return SendClientMessage(playerid, ERROR, "You must be in the driver seat to activite or deactivate the engine!");
if(vehEngine[vehicleid] == 1)
{
format(globalstring,sizeof(globalstring),"%s twists their vehicle's key in the ignition left, turning it off.",RPName(playerid));
nearByMessage(playerid,COLOR_PURPLE,globalstring);
SetVehicleParamsEx(vehicleid,0,lights,alarm,doors,bonnet,boot,objective);
vehEngine[vehicleid] = 0;
KillTimer(FuelTimerz[playerid]);
}
else if(vehEngine[vehicleid] == 0)
{
if(vehicleid == pVehicle1[playerid] || vehicleid == pVehicle2[playerid] || vehicleid == pVehicle3[playerid])
{
if(pvInfo[playerid][playerVehicleGas] >= 1)
{
if(model == 510) return SendClientMessage(playerid, ERROR, "Mountain bikes do not have engines!");
if(vehEngine[vehicleid] == 0)
{
vehEngine[vehicleid] = 2;
SetTimerEx("StartEngine", 1500, 0, "i", playerid);
format(globalstring,sizeof(globalstring),"%s twists their vehicle's key in the ignition right, attempting to turn it on.",RPName(playerid));
nearByMessage(playerid,COLOR_PURPLE,globalstring);
}
else if(vehEngine[vehicleid] == 2)
{
SetTimerEx("StartEngine", 1500, 0, "i", playerid);
format(globalstring,sizeof(globalstring),"%s twists their vehicle's key in the ignition right, attempting to turn it on.",RPName(playerid));
nearByMessage(playerid,COLOR_PURPLE,globalstring);
}
}
else return SendClientMessage(playerid, ERROR, "This vehicle is out of fuel and the engine cannot be turned on!");
}
else if(vInfo[vehicleid][vVehicleScriptID] >= 0)
{
if(vInfo[vehicleid][vGasoline] >= 1)
{
if(model == 510) return SendClientMessage(playerid, ERROR, "Mountain bikes do not have engines!");
if(vehEngine[vehicleid] == 0)
{
vehEngine[vehicleid] = 2;
SetTimerEx("StartEngine", 1500, 0, "i", playerid);
format(globalstring,sizeof(globalstring),"%s twists their vehicle's key in the ignition right, attempting to turn it on.",RPName(playerid));
nearByMessage(playerid,COLOR_PURPLE,globalstring);
}
else if(vehEngine[vehicleid] == 2)
{
SetTimerEx("StartEngine", 1500, 0, "i", playerid);
format(globalstring,sizeof(globalstring),"%s twists their vehicle's key in the ignition right, attempting to turn it on.",RPName(playerid));
nearByMessage(playerid,COLOR_PURPLE,globalstring);
}
}
else
{
SendClientMessage(playerid, ERROR, "This vehicle is out of fuel and the engine cannot be turned on!");
}
}
else
{
RemovePlayerFromVehicle(playerid);
}
}
return 1;
}
pawn Код:
if(newstate == PLAYER_STATE_DRIVER)
{
new vehicleid = GetPlayerVehicleID(playerid);
if(vehicleid != pVehicle1[playerid] || vehicleid != pVehicle2[playerid] || vehicleid != pVehicle3[playerid])
{
if(vInfo[vehicleid][vVehicleScriptID] >= 0)
{
return 0;
}
else
{
if(pInfo[playerid][pHotwiringKit] == 0)
{
SendClientMessage(playerid, ERROR, "You do not have the key to this vehicle, nor can you hotwire it without a hotwiring kit.");
RemovePlayerFromVehicle(playerid);
}
else
{
SendClientMessage(playerid, 0x6A5FAFFF, "You have a hotwiring kit; use /hotwire to hotwire this vehicle.");
}
print("This vehicle is owned!!");
}
}
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(vInfo[i][vVehicleScriptID] == GetPlayerVehicleID(playerid) && vInfo[i][vVehicleFaction] != 0 && vInfo[i][vVehicleFaction] != pInfo[playerid][pFaction])
{
if(vInfo[i][vFactionRank] > pInfo[playerid][pFactionRank])
{
switch(vInfo[i][vFactionRank])
{
case 1: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName1]);
case 2: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName2]);
case 3: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName3]);
case 4: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName4]);
case 5: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName5]);
case 6: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName6]);
case 7: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName7]);
case 8: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName8]);
case 9: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName9]);
case 10: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName10]);
}
SendClientMessage(playerid, ERROR, globalstring);
}
else
{
switch(vInfo[i][vFactionRank])
{
case 1: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName1]);
case 2: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName2]);
case 3: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName3]);
case 4: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName4]);
case 5: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName5]);
case 6: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName6]);
case 7: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName7]);
case 8: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName8]);
case 9: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName9]);
case 10: format(globalstring, sizeof(globalstring), "This vehicle is locked from your usage. [%s - %s and above]", fInfo[vInfo[playerid][vVehicleFaction]][fName], fInfo[vInfo[i][vVehicleFaction]][fRankName10]);
}
SendClientMessage(playerid, ERROR, globalstring);
}
RemovePlayerFromVehicle(playerid);
}
}
}
PHP код:
[17:38:50] CMySQLHandler::Query(SELECT * FROM playervehicles WHERE playerOwnerID = '1') - Successfully executed.
[17:38:50] >> mysql_store_result( Connection handle: 1 )
[17:38:50] CMySQLHandler::StoreResult() - Result was stored.
[17:38:50] >> mysql_retrieve_row( Connection handle: 1 )
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:50] CMySQLHandler::FetchField("playerOwnedVehicleID") - 1
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:50] CMySQLHandler::FetchField("playerVehicleSlot") - 1
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:50] CMySQLHandler::FetchField("playerVehicleModel") - 402
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:50] CMySQLHandler::FetchField("playerVehicleColor1") - 1
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:50] CMySQLHandler::FetchField("playerVehicleColor2") - 1
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:50] CMySQLHandler::FetchField("playerVehicleX") - 45.3098
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:50] CMySQLHandler::FetchField("playerVehicleY") - 1161.1
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:50] CMySQLHandler::FetchField("playerVehicleZ") - 18.5693
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:50] CMySQLHandler::FetchField("playerVehicleRot") - 360
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:50] CMySQLHandler::FetchField("playerVehicleGas") - 100
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:50] CMySQLHandler::FetchField("playerVehicleLocked") - 0
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:50] CMySQLHandler::FetchField("playerTrunkArmour") - 0
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:50] CMySQLHandler::FetchField("playerTrunkCash") - 0
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:50] CMySQLHandler::FetchField("playerTrunkWeapon1") - 0
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:50] CMySQLHandler::FetchField("playerTrunkWeapon2") - 0
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:50] CMySQLHandler::FetchField("playerTrunkWeapon3") - 0
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:50] CMySQLHandler::FetchField("playerTrunkAmmo1") - 0
[17:38:50] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:51] CMySQLHandler::FetchField("playerTrunkAmmo2") - 0
[17:38:51] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:51] CMySQLHandler::FetchField("playerTrunkAmmo3") - 0
[17:38:51] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:51] CMySQLHandler::FetchField("playerTrunkPot") - 0
[17:38:51] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:51] CMySQLHandler::FetchField("playerTrunkCocaine") - 0
[17:38:51] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:51] CMySQLHandler::FetchField("playerTrunkMedicalKit") - 0
[17:38:51] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:51] CMySQLHandler::FetchField("playerTrunkMaterials") - 0
[17:38:51] >> mysql_fetch_field_row( Connection handle: 1 )
[17:38:51] CMySQLHandler::FetchField("playerOwnerID") - 1
[17:38:51] >> mysql_retrieve_row( Connection handle: 1 )
[17:38:51] >> mysql_free_result( Connection handle: 1 )
[17:38:51] CMySQLHandler::FreeResult() - Result was successfully free'd.
[17:38:51] >> mysql_free_result( Connection handle: 1 )
[17:38:51] CMySQLHandler::FreeResult() - The result is already empty.
[17:39:12] >> mysql_query( Connection handle: 1 )
Nmader
Fellow Scripter