Checkpoint help -
iGetty - 27.05.2012
Below I have posted the code for my trunk system, I'm having an issue with the checkpoints.
When I enter the checkpoint, nothing happens at all, so I can't see the SendClientMessage that it shows in the "OnPlayerEnterCheckpoint", or the "OnPlayerLeaveCheckpoint".
Does anybody know what's the problem here?
Thanks!
pawn Code:
command(opentrunk, playerid, params[])
{
new model = GetVehicleModel(GetPlayerVehicleID(playerid)), string[256];
new iVehicleID = GetPlayerVehicleID(playerid);
if(model == 509 || model == 481 || model == 510 || model == 462 || model == 448 || model == 581 || model == 522 || model == 461 || model == 521 || model == 523 || model == 463 || model == 586 || model == 468 || model == 471) return SendClientMessage(playerid, WHITE, "This vehicle doesn't have a trunk.");
else
{
if(AccessingTrunk[playerid] == 0)
{
if(OwnedVeh(iVehicleID) != 0)
{
if(strmatch(vInfo[OwnedVeh(iVehicleID)][vOwner], pName(playerid)))
{
new Float:Pos[5];
GetPlayerPos(playerid, Pos[1], Pos[2], Pos[3]);
TrunkXY(playerid, Pos[1], Pos[2], 3);
format(string, sizeof(string), "* %s pops a button to open the trunk *", RemoveUnderScore(playerid));
CloseMessage(playerid, ACTION, string);
AccessingTrunk[playerid] = 1;
RemovePlayerFromVehicle(playerid);
}
else return SendClientMessage(playerid, YELLOW, "This vehicle isn't yours, therefore you can't use the trunk.");
}
else return SendClientMessage(playerid, WHITE, "This vehicle hasn't got a trunk installed.");
}
else return SendClientMessage(playerid, WHITE, "You are already accessing this vehicle's trunk.");
}
return 1;
}
pawn Code:
stock TrunkXY(playerid, &Float:x2, &Float:y2, Float:distance)
{
new Float:a;
GetPlayerPos(playerid, x2, y2, a);
GetPlayerFacingAngle(playerid, a);
if(GetPlayerVehicleID(playerid))
{
GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
}
x2 += (distance * floatsin(-a+180, degrees));
y2 += (distance * floatcos(-a+180, degrees));
SetPlayerCheckpoint(playerid, x2, y2, a, 1.0);
}
pawn Code:
public OnPlayerEnterCheckpoint(playerid)
{
if(AccessingTrunk[playerid] == 1)
{
new string[128];
format(string, sizeof(string), "To use this vehicle's trunk, use the command '/trunk'.");
SendClientMessage(playerid, WHITE, string);
}
return 1;
}
public OnPlayerLeaveCheckpoint(playerid)
{
if(AccessingTrunk[playerid] == 1)
{
DisablePlayerCheckpoint(playerid);
AccessingTrunk[playerid] = 0;
SendClientMessage(playerid, WHITE, "You can no longer use this vehicle's trunk.");
}
return 1;
}
Re: Trunk system. -
vvhy - 27.05.2012
show where the checkpoints are created probably OnGameModeInit or OnPlayerSpawn
Re: Trunk system. -
iGetty - 27.05.2012
It's here:
pawn Code:
stock TrunkXY(playerid, &Float:x2, &Float:y2, Float:distance)
{
new Float:a;
GetPlayerPos(playerid, x2, y2, a);
GetPlayerFacingAngle(playerid, a);
if(GetPlayerVehicleID(playerid))
{
GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
}
x2 += (distance * floatsin(-a+180, degrees));
y2 += (distance * floatcos(-a+180, degrees));
SetPlayerCheckpoint(playerid, x2, y2, a, 1.0);
}
In the stock..
Re: Trunk system. -
saiberfun - 27.05.2012
From my point of view I'd say that the player doesn't have "AccessingTrunk[playerid] == 1" yet when entering the checkpoint.
Which should result in nothing happening.
Try to debug it by giving out the value on entering the checkpoint.
So you see it's either 0 or 1.
Re: Trunk system. -
iGetty - 27.05.2012
"AccessingTrunk[playerid] = 1;" is on the command mate.
I'll try debugging soon.
Thanks!
Re: Trunk system. -
ReneG - 27.05.2012
One thing, you don't need a string size of 256 for a clientmessage, messages have the max size of 128, and 256 is a waste of memory.
About the TrunkXY you are doing this.
pawn Code:
stock TrunkXY(playerid, &Float:x2, &Float:y2, Float:distance)
{
new Float:a;
GetPlayerPos(playerid, x2, y2, a);
GetPlayerFacingAngle(playerid, a);
if(GetPlayerVehicleID(playerid))
{
GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
}
x2 += (distance * floatsin(-a+180, degrees));
y2 += (distance * floatcos(-a+180, degrees));
SetPlayerCheckpoint(playerid, x2, y2, a, 1.0);
}
I'm not sure if this is causing a problem, but the Z position of the checkpoint will always be the angle the player is facing. That means if the player is on Mount Chilliad, then the checkpoint might appear like a million feet underground. Just add a z float like so.
pawn Code:
stock TrunkXY(playerid, &Float:x2, &Float:y2, Float:distance)
{
new
Float:a,
Float:z
;
GetPlayerPos(playerid, x2, y2, z);
GetPlayerFacingAngle(playerid, a);
if(GetPlayerVehicleID(playerid))
{
GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
}
x2 += (distance * floatsin(-a+180, degrees));
y2 += (distance * floatcos(-a+180, degrees));
SetPlayerCheckpoint(playerid, x2, y2, z, 1.0);
}
Anything else can be solved by debugging a lot of the code, good luck.
Re: Trunk system. -
iGetty - 27.05.2012
The checkpoint actually shows though? It's just when I'm in the checkpoint it does nothing.
Re: Trunk system. -
iGetty - 27.05.2012
pawn Code:
stock TrunkXY(playerid, &Float:x2, &Float:y2, Float:distance)
{
new Float:a;
GetPlayerPos(playerid, x2, y2, a);
print("Player positions received");
GetPlayerFacingAngle(playerid, a);
print("Player facing angle received");
if(GetPlayerVehicleID(playerid))
{
printf("Vehicle ID checked: %d", GetPlayerVehicleID(playerid));
GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
}
print("Z angle");
x2 += (distance * floatsin(-a+180, degrees));
printf("x2 = %f", x2);
y2 += (distance * floatcos(-a+180, degrees));
printf("y2 = %f", y2);
SetPlayerCheckpoint(playerid, x2, y2, a, 1.0);
print("Checkpoint created.");
AccessingTrunk[playerid] = 1;
printf("AccessingTrunk = %d", AccessingTrunk[playerid]);
}
So I added that and in the console it printed:
Code:
[20:03:21] Player positions received
[20:03:21] Player facing angle received
[20:03:21] Vehicle ID checked: 1
[20:03:21] Z angle
[20:03:21] x2 = 763.608520
[20:03:21] y2 = 348.890686
[20:03:21] Checkpoint created.
[20:03:21] AccessingTrunk = 1
Under OnPlayerEnterCheckpoint I added this: Also on the LeaveCheckpoint this:
pawn Code:
public OnPlayerEnterCheckpoint(playerid)
{
print("OnPlayerEnterCheckpoint called");
if(AccessingTrunk[playerid] == 1)
{
print("Trunk accessing is checked.");
new string[128];
format(string, sizeof(string), "To use this vehicle's trunk, use the command '/trunk'.");
SendClientMessage(playerid, WHITE, string);
print("Message sent.");
}
return 1;
}
public OnPlayerLeaveCheckpoint(playerid)
{
print("OnPlayerLeaveCheckpoint called");
if(AccessingTrunk[playerid] == 1)
{
DisablePlayerCheckpoint(playerid);
print("DisablePlayerCheckpoint(playerid);");
AccessingTrunk[playerid] = 0;
print("AccessingTrunk");
SendClientMessage(playerid, WHITE, "You can no longer use this vehicle's trunk.");
}
return 1;
}
It didn't call.
Edit: Meant to edit the other post, sorry!
Re: Trunk system. -
ReneG - 27.05.2012
Try printing the status of AccessingTrunk in the OnPlayerEnterCheckPoint.
Re: Trunk system. -
iGetty - 27.05.2012
The OnPlayerEnterCheckpoint doesn't get called?