PDA

View Full Version : Checkpoint problem


knackworst
08/10/2011, 09:31 PM
Hi, I got a little problem
For my server I made a driving mission, to do so I used CPS:
new Mcheck[2];

ok, so in my code i added something that creates the checkpoint:
Mcheck[0] = CreateDynamicCP(mStart_x, mStart_y, mStart_z, 2.0, -1, -1, playerid, 400000.0);

ok so the onplayerenterdyncp callback:
forward OnPlayerEnterDynamicCP(playerid, checkpointid);
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{

new vehicle;
vehicle = GetVehicleModel(GetPlayerVehicleID(playerid));

if(checkpointid == Mcheck[0])
{
new NewVehicleID = GetPlayerVehicleID(playerid);
if(OldVehicleID[playerid] != NewVehicleID) return SendClientMessage(playerid,COLOR_RED,"This vehicle does not contain a passenger!");
// stop previous CP
DestroyDynamicCP(Mcheck[0]);
Mcheck[1] = CreateDynamicCP(mInfo[playerid][Del_x], mInfo[playerid][Del_y], mInfo[playerid][Del_z], 2.0, -1, -1, playerid, 400000.0);
}

if(checkpointid == Mcheck[1])
{
SendClientMessage(playerid,COLOR_RED,"completed the mission");
}

ok so this should just create a new CP when enterring the first one
but when I enter the first one I get the message from the Second one,
and wehn I enter the second one I get the message from the Second one again...
any help?

=WoR=G4M3Ov3r
08/10/2011, 10:19 PM
Its because you only put SendClientMessage once, therefore it'll show in both cases.

Babul
08/10/2011, 10:33 PM
for checkpoint-decisions, try switch{case{}case{}} instead of if{}if{}. if's will get called even if the first one got triggered when you didnt use an else-if. even if you use the else, then it will loop through them until a decision is done or w/o result: it uses CPU time if you extend the amount later.
the switch/case avoids that behavior, it prepares a quick decision "table", and for one case it triggers the action. well, i describe it horribly, just look at this piece:

new NewVehicleID = GetPlayerVehicleID(playerid);
switch(checkpointid)
{
case Mcheck[0]:
{
if(OldVehicleID[playerid] != NewVehicleID) return SendClientMessage(playerid,COLOR_RED,"This vehicle does not contain a passenger!");
// stop previous CP
DestroyDynamicCP(Mcheck[0]);
Mcheck[1] = CreateDynamicCP(mInfo[playerid][Del_x], mInfo[playerid][Del_y], mInfo[playerid][Del_z], 2.0, -1, -1, playerid, 400000.0);
}
case Mcheck[1]:
{
SendClientMessage(playerid,COLOR_RED,"completed the mission");
}
}

iam curious if this works. didnt test it indeed ^^

knackworst
08/10/2011, 10:36 PM
ty, but now I get this:
C:\Users\William\Documents\Famous' World\Famous' World\gamemodes\Famous.pwn(4535) : error 008: must be a constant expression; assumed zero
C:\Users\William\Documents\Famous' World\Famous' World\gamemodes\Famous.pwn(4542) : error 008: must be a constant expression; assumed zero

the lines are the case Mcheck, stuff

Babul
08/10/2011, 10:56 PM
oops, stupid me. the Mcheck[] can get assigned any value, the case needs a constant... so by adding these

#define CheckpointOrder0 0
#define CheckpointOrder1 1

.. and adding one more line for the order, stored per player:

new Mcheck[2];
new McheckOrder[MAX_PLAYERS];

when you create your checkpoint, the McheckOrder[playerid] will automatically be set to 0, or CheckpointOrder0, as initial value btw..
use it like this:

new NewVehicleID = GetPlayerVehicleID(playerid);
switch(McheckOrder[playerid])
{
case CheckpointOrder1:
{
if(OldVehicleID[playerid] != NewVehicleID) return SendClientMessage(playerid,COLOR_RED,"This vehicle does not contain a passenger!");
// stop previous CP
DestroyDynamicCP(Mcheck[0]);
Mcheck[1] = CreateDynamicCP(mInfo[playerid][Del_x], mInfo[playerid][Del_y], mInfo[playerid][Del_z], 2.0, -1, -1, playerid, 400000.0);
McheckOrder[playerid]=CheckpointOrder1;
}
case CheckpointOrder1:
{
SendClientMessage(playerid,COLOR_RED,"completed the mission");
McheckOrder[playerid]=CheckpointOrder0;// or simply 0;
}
}

did i forget anything?
edit: the refreshing didnt work for some minutes here. weird.. first CP needs to be 0 indeed ^^
case CheckpointOrder0:
edit: sig removed. 1 is ok for a page lol

knackworst
08/10/2011, 11:05 PM
shouldnt be the first cporder be 0?
and also, how can I add more of them now?
like 3 and 4?

Babul
08/10/2011, 11:13 PM
hm. after thinking for 10 seconds more, the #defines are not needed. the checkpoints will get created in order i bet :)

const MaxCheckpoints=4;
new Mcheck[MaxCheckpoints];
new McheckOrder[MAX_PLAYERS];


new NewVehicleID = GetPlayerVehicleID(playerid);
switch(McheckOrder[playerid])
{
case 0:
{
if(OldVehicleID[playerid] != NewVehicleID) return SendClientMessage(playerid,COLOR_RED,"This vehicle does not contain a passenger!");
// stop previous CP
DestroyDynamicCP(Mcheck[0]);
Mcheck[1] = CreateDynamicCP(mInfo[playerid][Del_x], mInfo[playerid][Del_y], mInfo[playerid][Del_z], 2.0, -1, -1, playerid, 400000.0);
McheckOrder[playerid]=1;
}
case 1:
{
SendClientMessage(playerid,COLOR_RED,"completed 1/2 of the mission");
DestroyDynamicCP(Mcheck[1]);
Mcheck[2] = CreateDynamicCP(mInfo[playerid][Del_x], mInfo[playerid][Del_y], mInfo[playerid][Del_z], 2.0, -1, -1, playerid, 400000.0);
McheckOrder[playerid]=2;
}
case 2:
{
SendClientMessage(playerid,COLOR_RED,"completed 3/4 of the mission");
DestroyDynamicCP(Mcheck[2]);
Mcheck[3] = CreateDynamicCP(mInfo[playerid][Del_x], mInfo[playerid][Del_y], mInfo[playerid][Del_z], 2.0, -1, -1, playerid, 400000.0);
McheckOrder[playerid]=3;
}
case 3:
{
SendClientMessage(playerid,COLOR_RED,"completed the mission");
DestroyDynamicCP(Mcheck[3]);
McheckOrder[playerid]=0;
}
}

knackworst
08/10/2011, 11:17 PM
I wont be able to script no more for 6 days, and im on ipod now
Still i believe it will work... But i got one more quest, whats constant for?

Babul
09/10/2011, 08:02 PM
const=constant. it cannot be changed later - a simple variable can be changed, so it causes the "constant expresion" error.