[Help] Respawning vehicles & Timers
#1

Hello everyone. Today I created a command called /dropcar. Which, creates a checkpoint at a certain location if you are in a vehicle. You drive to this location, and you get a random amount of money. Seems simple. However, I can not for the life of me get the vehicle to respawn after the player has entered the checkpoint.

Код:
CMD:dropcar(playerid, params[])
{
    {
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not in a vehicle!");
    SetPlayerCheckpoint(playerid, -1697.0311,-92.7514,3.5544, 5.0);
    }

    if (IsPlayerInCheckpoint(playerid))
    {
    if(IsPlayerInAnyVehicle(playerid))
    GivePlayerMoney(playerid, random(1000) + 657);
    SetVehicleToRespawn(playerid);
    SendClientMessage(playerid, COLOR_WHITE, "You dopped a car! You must now wait 15 minutes before doing this command again.");
    }
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 5, -1697.0311,-92.7514,3.5544))
     {
       if(IsPlayerInAnyVehicle(playerid))
          {
          GivePlayerMoney(playerid, random(1000) + 657);
          SendClientMessage(playerid, COLOR_WHITE, "You dopped a car! You must now wait 15 minutes before doing this command again.");
          DisablePlayerCheckpoint(playerid);
          }
       new vehicleid;
       if(IsPlayerInVehicle(playerid, vehicleid))
       {
          SetVehicleToRespawn(vehicleid);
          }
          
       }
	return 1;
}
(It looks like the indentation went a little bit off when I pasted it, sorry.)

ALSO:

If someone could tell me how to put a 15 second time limit between successful uses of the command, that would be awesome.

(I am a PAWN noob so please do not get angry if I am a little off.
Reply
#2

Nah, you don't beg for complete script so I'll be glad to help.

First of all, watch your braces ( https://sampwiki.blast.hk/wiki/Control_Structures#if )

pawn Код:
new bool:DropCooloff[MAX_PLAYERS char];
CMD:dropcar(playerid, params[])
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not in a vehicle!");
    if(DropCooloff{playerid}) return SendClientMessage(playerid, COLOR_RED, "15 minutes cooloff!");
    SetPlayerCheckpoint(playerid, -1697.0311,-92.7514,3.5544, 5.0);
    //IsPlayerInAnyVehicle(playerid) is redundant, as we've checked it on top of function
    return 1;
}
SuccessMission(playerid) {
    GivePlayerMoney(playerid, random(1000) + 657);
    SetVehicleToRespawn(playerid);
    DropCooloff{playerid} = true;
    SetTimerEx("Cooloff", 1000*60*15, 0, "i", playerid);
    SendClientMessage(playerid, COLOR_WHITE, "You dopped a car! You must now wait 15 minutes before doing this command again.");
    DisablePlayerCheckpoint(playerid);
}
forward Cooloff(playerid);
public Cooloff(playerid) {
    return (DropCooloff{playerid} = false);
}
public OnPlayerEnterCheckpoint(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 5, -1697.0311,-92.7514,3.5544))
    {
        if(IsPlayerInAnyVehicle(playerid)) {
            SuccessMission(playerid);
            SetVehicleToRespawn(GetPlayerVehicleID(playerid))
        }      
    }
    return 1;
}
#e: now with timer!
Reply
#3

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Nah, you don't beg for complete script so I'll be glad to help.

First of all, watch your braces ( https://sampwiki.blast.hk/wiki/Control_Structures#if )

pawn Код:
CMD:dropcar(playerid, params[])
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not in a vehicle!");
    SetPlayerCheckpoint(playerid, -1697.0311,-92.7514,3.5544, 5.0);
    //IsPlayerInAnyVehicle(playerid) is redundant, as we've checked it on top of function
    return 1;
}
SuccessMission(playerid) {
    GivePlayerMoney(playerid, random(1000) + 657);
    SetVehicleToRespawn(playerid);
    SendClientMessage(playerid, COLOR_WHITE, "You dopped a car! You must now wait 15 minutes before doing this command again.");
    DisablePlayerCheckpoint(playerid);
}
public OnPlayerEnterCheckpoint(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 5, -1697.0311,-92.7514,3.5544))
    {
        if(IsPlayerInAnyVehicle(playerid)) {
            SuccessMission(playerid);
            //GetPlayerVehicleID returns id of car in which player is currently in. It doesn't check if he's driver though
            SetVehicleToRespawn(GetPlayerVehicleID(playerid))
        }      
    }
    return 1;
}
Awesome! Thank you so much. And I will be more careful in the future with my braces.
Reply
#4

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Nah, you don't beg for complete script so I'll be glad to help.

First of all, watch your braces ( https://sampwiki.blast.hk/wiki/Control_Structures#if )

pawn Код:
new bool:DropCooloff[MAX_PLAYERS char];
CMD:dropcar(playerid, params[])
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not in a vehicle!");
    if(DropCooloff{playerid}) return SendClientMessage(playerid, COLOR_RED, "15 minutes cooloff!");
    SetPlayerCheckpoint(playerid, -1697.0311,-92.7514,3.5544, 5.0);
    //IsPlayerInAnyVehicle(playerid) is redundant, as we've checked it on top of function
    return 1;
}
SuccessMission(playerid) {
    GivePlayerMoney(playerid, random(1000) + 657);
    SetVehicleToRespawn(playerid);
    DropCooloff{playerid} = true;
    SetTimerEx("Cooloff", 1000*60*15, 0, "i", playerid);
    SendClientMessage(playerid, COLOR_WHITE, "You dopped a car! You must now wait 15 minutes before doing this command again.");
    DisablePlayerCheckpoint(playerid);
}
forward Cooloff(playerid);
public Cooloff(playerid) {
    return (DropCooloff{playerid} = false);
}
public OnPlayerEnterCheckpoint(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 5, -1697.0311,-92.7514,3.5544))
    {
        if(IsPlayerInAnyVehicle(playerid)) {
            SuccessMission(playerid);
            SetVehicleToRespawn(GetPlayerVehicleID(playerid))
        }      
    }
    return 1;
}
#e: now with timer!
Thank you so much! Awesome
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)