SA-MP Forums Archive
What's wrong? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: What's wrong? (/showthread.php?tid=184729)



What's wrong? - Gh0sT_ - 21.10.2010

Код:
/* CREDITS:
** Blabla93 A.K.A [TGG]Bill | Coding the include
** [HiC]TheKiller, Kwarde & RealCop228 for the suggestion of adding a race checkpoints
** Mauzen for having the idea to add OnPlayerMission(playerid) call back!
*/

/* CHANGE LOG
*** VERSION 2.0
** You can now cancel a players mission but using CancelPlayersCurrentMission(playerid);
** You can now add custom stuff to when the player finishs the mission using public OnPlayerFinishMission(playerid)
** If you un comment "#define USE_RACE_CHECKPOINT" the Include will use race checkpoints instead of regulare checkpoints!
** You can adjust the amount a player looses when they loose there trailer for 30 seconds if TrailerCheck is enabled using "#define COST_OF_LOST_GOODS"
** You can change the size of the checkpoints using "#define CHECKPOINT_SIZE"
*/

#include <a_samp>
#define COST_OF_LOST_GOODS 1500
#define CHECKPOINT_SIZE 7
#define USE_RACE_CHECKPOINT   // Un comment this line to enable Race Checkoints!

/* Only change this if USE_RACE_CHECKPOINT is enabled! */
#define RACE_CHECKPOINT_TYPE 1
/* KEY
** 0-Normal
** 1-Finish
** 2-Nothing(Only the checkpoint without anything on it)
** 3-Air normal
** 4-Air finish
*/

enum missioninfo
{
//    MissionText[200],  For Future Versions
	Pay,
	Checkpoint,
	CheckpointID,
	Float:Lastx,
	Float:Lasty,
	Float:Lastz,
 	TrailerID,
 	bool:AllowTrailerCheck,
 	TrailerCheckCount
}
new minfo[MAX_PLAYERS][missioninfo];

new LTimer[MAX_PLAYERS];
new ULTimer[MAX_PLAYERS];
new TrailerCheckTimer[MAX_PLAYERS];
new strn[250];
#define RAUDONA 0xFF0000FF
#define MELYNA 0x00FFFFFF
#define NustatytiBusena     		TogglePlayerControllable
#include <streamer>

stock CreatePlayerMission(playerid, bool:TrailerCheck, MissionPay, Float:Startx, Float:Starty, Float:Startz, Float:Endx, Float:Endy, Float:Endz)
{
    if (TrailerCheck == true)
	{
		new pvehiclemodel = GetVehicleModel(GetPlayerVehicleID(playerid));
		if (pvehiclemodel == 403 || pvehiclemodel == 514 || pvehiclemodel == 515)
		{
		    minfo[playerid][AllowTrailerCheck] = true;
		}
		else return 1;
	}
	
	minfo[playerid][Pay] = MissionPay;
	minfo[playerid][Lastx] = Endx;
	minfo[playerid][Lasty] = Endy;
	minfo[playerid][Lastz] = Endz;
	minfo[playerid][CheckpointID] = 1;
//	minfo[playerid][MissionText] = Mission;
	#if defined USE_RACE_CHECKPOINT
        minfo[playerid][Checkpoint] = CreateDynamicRaceCP(RACE_CHECKPOINT_TYPE, Startx, Starty, Startz, Endx, Endy, Endz, CHECKPOINT_SIZE, -1, -1, -1, 100);
	#else
        minfo[playerid][Checkpoint] = CreateDynamicCP(playerid, Startx, Starty, Startz, CHECKPOINT_SIZE, -1, -1, -1, 100);
	#endif
  	return 1;
}

stock CancelPlayersCurrentMission(playerid)
{
	if (minfo[playerid][AllowTrailerCheck] == true)
	{
        KillTimer(TrailerCheckTimer[playerid]);
	    minfo[playerid][TrailerCheckCount] = 0;
	    minfo[playerid][AllowTrailerCheck] = false;
	}
    format(strn, sizeof(strn), "Jūs praradote $%d dėl krovinio praradimo.", COST_OF_LOST_GOODS);
    SendClientMessage(playerid, RAUDONA, strn);
    GivePlayerMoney(playerid, -COST_OF_LOST_GOODS);
    #if defined USE_RACE_CHECKPOINT
    	DestroyDynamicRaceCP(playerid);
	#else
	    DestroyDynamicCP(playerid);
	#endif
	return 1;
}

forward M_OnPlayerConnect(playerid);
public M_OnPlayerConnect(playerid)
{
	minfo[playerid][Pay] = 0;
	minfo[playerid][Lastx] = 0;
	minfo[playerid][Lasty] = 0;
	minfo[playerid][Lastz] = 0;
	minfo[playerid][Checkpoint] = 0;
	minfo[playerid][CheckpointID] = 0;
	minfo[playerid][AllowTrailerCheck] = false;
	minfo[playerid][TrailerCheckCount] = 0;
//	minfo[playerid][MissionText] = "";
}


forward M_OnPlayerDisconnect(playerid);
public M_OnPlayerDisconnect(playerid)
{
	if (minfo[playerid][CheckpointID] == 1)
	{
	    KillTimer(LTimer[playerid]);
	}
	if (minfo[playerid][CheckpointID] == 2)
	{
	    KillTimer(ULTimer[playerid]);
	    if (minfo[playerid][AllowTrailerCheck] == true)
		{
		    KillTimer(TrailerCheckTimer[playerid]);
		}
	}
	return 1;
}


forward M_OnPlayerEnterCheckpoint(playerid);
public M_OnPlayerEnterCheckpoint(playerid)
{
	if (minfo[playerid][CheckpointID] == 1)
	{
		if (minfo[playerid][AllowTrailerCheck] == true)
		{
			if (IsTrailerAttachedToVehicle(GetPlayerVehicleID(playerid)))
			{
				minfo[playerid][TrailerID] = GetVehicleTrailer(GetPlayerVehicleID(playerid));
				TrailerCheckTimer[playerid] = SetTimerEx("TrailerCheck", 1000, true, "d" , playerid);
			}
			else return SendClientMessage(playerid, MELYNA, "Jūs neesate prisikabinę priekabos!");

		}
        SendClientMessage(playerid, MELYNA, "Kraunama, praљome palaukti.");
        NustatytiBusena(playerid, 0);
        SetPVarInt(playerid,"Iskrauna", 1);
        LTimer[playerid] = SetTimerEx("Loading", 15000, false, "d" , playerid);
	}
	else if (minfo[playerid][CheckpointID] == 2)
	{
	    if (minfo[playerid][AllowTrailerCheck] == true)
		{
		    if (IsTrailerAttachedToVehicle(GetPlayerVehicleID(playerid)))
			{
			    if (minfo[playerid][TrailerID] == GetVehicleTrailer(GetPlayerVehicleID(playerid)))
			    {
			        KillTimer(TrailerCheckTimer[playerid]);
			        minfo[playerid][AllowTrailerCheck] = false;
				}
				else
				{
				    SendClientMessage(playerid, MELYNA, "Jūs neesate prisikabinę priekabos, su kuria pradėjote veћti krovinį.");
				}
	        }
			else return SendClientMessage(playerid, MELYNA, "Jūs neesate prisikabinę priekabos.");
		}
	    SendClientMessage(playerid,MELYNA, "Iљkraunama, praљome palaukti.");
        NustatytiBusena(playerid, 0);
        SetPVarInt(playerid,"Iskrauna", 1);
        ULTimer[playerid] = SetTimerEx("UnLoading", 30000, false, "d" , playerid);
	}
	return 1;
}

forward M_OnPlayerEnterRaceCheckpoint(playerid);
public M_OnPlayerEnterRaceCheckpoint(playerid)
{
    if (minfo[playerid][CheckpointID] == 1)
	{
		if (minfo[playerid][AllowTrailerCheck] == true)
		{
			if (IsTrailerAttachedToVehicle(GetPlayerVehicleID(playerid)))
			{
				minfo[playerid][TrailerID] = GetVehicleTrailer(GetPlayerVehicleID(playerid));
				TrailerCheckTimer[playerid] = SetTimerEx("TrailerCheck", 1000, true, "d" , playerid);
			}
			else return SendClientMessage(playerid, MELYNA, "Jūs neesate prisikabinę priekabos.");
		}
	    SendClientMessage(playerid, MELYNA, "Kraunama, praљome palaukti.");
	    NustatytiBusena(playerid, 0);
	    SetPVarInt(playerid,"Iskrauna", 1);
	    LTimer[playerid] = SetTimerEx("Loading", 15000, false, "d" , playerid);
	}
	else if (minfo[playerid][CheckpointID] == 2)
	{
	    if (minfo[playerid][AllowTrailerCheck] == true)
		{
		    if (IsTrailerAttachedToVehicle(GetPlayerVehicleID(playerid)))
			{
			    if (minfo[playerid][TrailerID] == GetVehicleTrailer(GetPlayerVehicleID(playerid)))
			    {
			        KillTimer(TrailerCheckTimer[playerid]);
			        minfo[playerid][AllowTrailerCheck] = false;
				}
				else
				{
				    SendClientMessage(playerid, MELYNA, "Jūs neesate prisikabinę priekabos, su kuria pradėjote veћti krovinį.!");
				}
	        }
			else return SendClientMessage(playerid, MELYNA, "Jūs neesate prisikabinę priekabos.");
		}
	    SendClientMessage(playerid, MELYNA, "Iљkraunama, praљome palaukti.");
        NustatytiBusena(playerid, 0);
        SetPVarInt(playerid,"Iskrauna", 1);
        ULTimer[playerid] = SetTimerEx("UnLoading", 30000,false, "d" , playerid);
	}
    return 1;
}

forward Loading(playerid);
public Loading(playerid)
{
    minfo[playerid][CheckpointID] = 2;
	NustatytiBusena(playerid, 1);
	SetPVarInt(playerid,"Iskrauna", 0);
	#if defined USE_RACE_CHECKPOINT
	    DestroyDynamicRaceCP(playerid);
        minfo[playerid][Checkpoint] = CreateDynamicRaceCP(RACE_CHECKPOINT_TYPE, minfo[playerid][Lastx], minfo[playerid][Lasty], minfo[playerid][Lastz], minfo[playerid][Lastx], minfo[playerid][Lasty], minfo[playerid][Lastz], CHECKPOINT_SIZE, -1, -1, -1, 100);
	#else
	    DestroyDynamicCP(playerid);
        minfo[playerid][Checkpoint] = CreateDynamicCP(playerid, minfo[playerid][Lastx], minfo[playerid][Lasty], minfo[playerid][Lastz], CHECKPOINT_SIZE, -1, -1, -1, 100);
	#endif
    return 1;
}

forward UnLoading(playerid);
public UnLoading(playerid)
{
    minfo[playerid][CheckpointID] = 0;
	NustatytiBusena(playerid, 1);
	SetPVarInt(playerid,"Iskrauna", 0);
	format(strn, sizeof(strn), "Sveikiname. Sėkmingai pristatėte krovinį, uћtai gavote $%d", minfo[playerid][Pay]);
	SendClientMessage(playerid, MELYNA, strn);
	GivePlayerMoney(playerid, minfo[playerid][Pay]);
    OnPlayerFinishMission(playerid);
	#if defined USE_RACE_CHECKPOINT
	    DestroyDynamicRaceCP(playerid);
	#else
	    DestroyDynamicCP(playerid);
	#endif
    return 1;
}

forward TrailerCheck(playerid);
public TrailerCheck(playerid)
{
    if (minfo[playerid][TrailerID] == GetVehicleTrailer(GetPlayerVehicleID(playerid)))
    {
        if (minfo[playerid][TrailerCheckCount] >= 1)
        {
	        new TimeRemaining;
	        TimeRemaining = 30 - minfo[playerid][TrailerCheckCount];
	        SendClientMessage(playerid, MELYNA, strn);
	        format(strn, sizeof(strn), "Jūs sėkmingai prisikabinote priekabą (%d sekundę(-es)", TimeRemaining);
		}
		minfo[playerid][TrailerCheckCount] = 0;
        return 1;
	}
	if (minfo[playerid][TrailerCheckCount] == 0)
	{
		SendClientMessage(playerid, MELYNA, "Jūs turite 30sekundћių prisikabinti savo priekabą.");
    	minfo[playerid][TrailerCheckCount]++;
	}
	minfo[playerid][TrailerCheckCount]++;
	if (minfo[playerid][TrailerCheckCount] >= 30)
	{
	    format(strn, sizeof(strn), "Jūs praradote $%d uћ prarastą priekabą.", COST_OF_LOST_GOODS);
	    SendClientMessage(playerid,RAUDONA, strn);
	    GivePlayerMoney(playerid, -COST_OF_LOST_GOODS);
        KillTimer(TrailerCheckTimer[playerid]);
	    minfo[playerid][TrailerCheckCount] = 0;
	    minfo[playerid][AllowTrailerCheck] = false;
	    #if defined USE_RACE_CHECKPOINT
	    	DestroyDynamicRaceCP(playerid);
		#else
		    DestroyDynamicCP(playerid);
		#endif
	}
	return 1;
}

forward OnPlayerFinishMission(playerid);
and.. when i start the mission, i didnt get CP at mini map, but CP created.. and, when i went to the CP, its work good, but checkpoint didnt destroy'ing, or when i type /cancelmission ( when truck unloaded ) and then /work - last mission CP didnt destroying, a