Checkpoint problem
#1

Hi, I got a little problem
For my server I made a driving mission, to do so I used CPS:
pawn Код:
new Mcheck[2];
ok, so in my code i added something that creates the checkpoint:
pawn Код:
Mcheck[0] = CreateDynamicCP(mStart_x, mStart_y, mStart_z, 2.0, -1, -1, playerid, 400000.0);
ok so the onplayerenterdyncp callback:
pawn Код:
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?
Reply
#2

Its because you only put SendClientMessage once, therefore it'll show in both cases.
Reply
#3

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 ^^
Reply
#4

ty, but now I get this:
pawn Код:
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
Reply
#5

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
Reply
#6

shouldnt be the first cporder be 0?
and also, how can I add more of them now?
like 3 and 4?
Reply
#7

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;
		}
	}
Reply
#8

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?
Reply
#9

const=constant. it cannot be changed later - a simple variable can be changed, so it causes the "constant expresion" error.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)