SA-MP Forums Archive
IsPlayerInCheckpoint - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: IsPlayerInCheckpoint (/showthread.php?tid=464304)



IsPlayerInCheckpoint [FIXED] - Kyance - 16.09.2013

So.. im trying to make a 'random' race, for my test server (Just for fun)..
But, since im don't really know, how the Checkpoint "system" works in Pawn, i get this error -

*bla bla bla*\test.pwn(510) : warning 202: number of arguments does not match definition

The script:


Код:
	if (!strcmp(cmdtext, "/rallymode", true)) {
	if (!IsPlayerInAnyVehicle(playerid)) return 1;
	new vehicleid = GetPlayerVehicleID(playerid);
	AddVehicleComponent(vehicleid, 1021);

	new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
	GetPlayerName(playerid, name, sizeof(name));

	format(string, sizeof(string), "%s has entered rally-mode!", name);
	SendClientMessageToAll(COLOR_RED, string);
	SendClientMessage(playerid, COLOR_GOLD, "Rally started!");
	SendClientMessage(playerid, COLOR_RED, "Head to the town!");
	SetPlayerCheckpoint(playerid,-2098.3074,-2246.2427,30.6250,3.5);
	
	if (IsPlayerInCheckpoint(playerid))
	SendClientMessageToAll(COLOR_GOLD, "%s has finished the Rally!", name);
	SendClientMessage(playerid, COLOR_GOLD, "Congratulations on finishing the rally!");
	GivePlayerMoney(playerid, 10000);
	return 1;
}
In short:
if (IsPlayerInCheckpoint(playerid))
SendClientMessageToAll(COLOR_GOLD, "%s has finished the Rally!", name);
These are the places, where it's going wrong.
I've tried setting a bracket, but i suppose i set it wrong..
Also, i sadly need to have 'specific' answers.
Like, if someone says 'You're missing a bracket there and there', it wont help for me..

Anyone that could try and help?;d


Re: IsPlayerInCheckpoint - Dragonsaurus - 16.09.2013

You have to format the message first.
pawn Код:
new string[64];
format(string, sizeof(string), "%s has finished the Rally!", name);
SendClientMessageToAll(COLOR_GOLD, string);



Re: IsPlayerInCheckpoint - Kyance - 16.09.2013

Quote:
Originally Posted by Dragonsaurus
Посмотреть сообщение
You have to format the message first.
pawn Код:
new string[64];
format(string, sizeof(string), "%s has finished the Rally!", name);
SendClientMessageToAll(COLOR_GOLD, string);
FIXED IT.

New problem: I receive the cash, before i even get to the checkpoint..


Re: IsPlayerInCheckpoint - Konstantinos - 16.09.2013

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp(cmdtext, "/rallymode", true))
    {
        if (!IsPlayerInAnyVehicle(playerid)) return 1;
        new vehicleid = GetPlayerVehicleID(playerid);
        AddVehicleComponent(vehicleid, 1021);
       
        new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
        GetPlayerName(playerid, name, sizeof(name));
       
        format(string, sizeof(string), "%s has entered rally-mode!", name);
        SendClientMessageToAll(COLOR_RED, string);
        SendClientMessage(playerid, COLOR_GOLD, "Rally started!");
        SendClientMessage(playerid, COLOR_RED, "Head to the town!");
        SetPlayerCheckpoint(playerid,-2098.3074,-2246.2427,30.6250,3.5);
        return 1;
    }
    return 0;
}

public OnPlayerEnterCheckpoint(playerid)
{
    SendClientMessageToAll(COLOR_GOLD, "%s has finished the Rally!", name);
    SendClientMessage(playerid, COLOR_GOLD, "Congratulations on finishing the rally!");
    GivePlayerMoney(playerid, 10000);
    DisablePlayerCheckpoint(playerid);
    return 1;
}
Only when a player enters a checkpoint, send the messages and give the money.


Re: IsPlayerInCheckpoint - Kyance - 16.09.2013

Konstantinos, it works completely perfect, till i arrive at the checkpoint.
When i arrive, it doesn't do anything


Re: IsPlayerInCheckpoint - Konstantinos - 16.09.2013

The only problem I could see is:
pawn Код:
SendClientMessageToAll(COLOR_GOLD, "%s has finished the Rally!", name);
You need to format it first.

Doesn't it send the message, give money or disable the checkpoint? It should.


Re: IsPlayerInCheckpoint - Kyance - 16.09.2013

Well, this is how the script looks currently..

Код:
	if (!strcmp(cmdtext, "/rallymode", true)) {
	if (!IsPlayerInAnyVehicle(playerid)) return 1;
	new vehicleid = GetPlayerVehicleID(playerid);
	AddVehicleComponent(vehicleid, 1021);

	new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
	GetPlayerName(playerid, name, sizeof(name));

	format(string, sizeof(string), "%s has entered rally-mode!", name);
	SendClientMessageToAll(COLOR_RED, string);
	SendClientMessage(playerid, COLOR_GOLD, "Rally started!");
	SendClientMessage(playerid, COLOR_RED, "Head to the town!");
	SetPlayerCheckpoint(playerid,-2098.3074,-2246.2427,30.6250,3.5);
	Create3DTextLabel("Slow down!", COLOR_RED, -2173.2581, -1997.3176, 118.9902, 35, 0, 0);
	if (IsPlayerInCheckpoint(playerid))
	{
		new stringz[64];
		format(stringz, sizeof(stringz), "%s has finished the Rally!", name);
		SendClientMessageToAll(COLOR_GOLD, string);
		SendClientMessage(playerid, COLOR_GOLD, "Congratulations on finishing the rally!");
		GivePlayerMoney(playerid, 10000);
	}
	return 1;
}
I arrive at the checkpoint, and nothing happens.
No text, no reward
[I re-named it to stringz, so it doesn't give an error that "string" is already in use or what so ever..]


Re: IsPlayerInCheckpoint - Konstantinos - 16.09.2013

Have a look at the code I gave you.

You code sets the checkpoint and if you're in a checkpoint the time you type /rallymode, only then you will get the money. You need to use OnPlayerEnterCheckpoint callback for that.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp(cmdtext, "/rallymode", true))
    {
        if (!IsPlayerInAnyVehicle(playerid)) return 1;
        new vehicleid = GetPlayerVehicleID(playerid);
        AddVehicleComponent(vehicleid, 1021);
       
        new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
        GetPlayerName(playerid, name, sizeof(name));
       
        format(string, sizeof(string), "%s has entered rally-mode!", name);
        SendClientMessageToAll(COLOR_RED, string);
        SendClientMessage(playerid, COLOR_GOLD, "Rally started!");
        SendClientMessage(playerid, COLOR_RED, "Head to the town!");
        SetPlayerCheckpoint(playerid,-2098.3074,-2246.2427,30.6250,3.5);
        Create3DTextLabel("Slow down!", COLOR_RED, -2173.2581, -1997.3176, 118.9902, 35, 0, 0);
        return 1;
    }
    return 0;
}

public OnPlayerEnterCheckpoint(playerid)
{
    new stringz[64], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    format(stringz, sizeof(stringz), "%s has finished the Rally!", name);
    SendClientMessageToAll(COLOR_GOLD, string);
    SendClientMessage(playerid, COLOR_GOLD, "Congratulations on finishing the rally!");
    GivePlayerMoney(playerid, 10000);
    DisablePlayerCheckpoint(playerid);
    return 1;
}



Re: IsPlayerInCheckpoint - Kyance - 16.09.2013

Works perfectly now, thanks a lot!