[HELP] Timer -.-
#1

Why doesn't this work? It compile but not work :S
PS: I dont know how to use Timers -.-'

pawn Код:
new IsSpawnedVehicle[MAX_PLAYERS];
new VehicleDestroyerTimer;

forward DestroySpawnedVehicle(playerid, vehicleid);

public OnPlayerExitVehicle(playerid, vehicleid)
{
    VehicleDestroyerTimer = SetTimer("DestroySpawnedVehicle", 10000, true);
    return 1;
}

public DestroySpawnedVehicle(playerid, vehicleid)
{
    if(IsSpawnedVehicle[playerid] == 1)
    {
        new currentvehivle;
        currentvehivle = GetPlayerVehicleID(playerid);
        DestroyVehicle(currentvehivle);
        IsSpawnedVehicle[playerid] = 0;
        KillTimer(VehicleDestroyerTimer);
        return 1;
    }
    return 0;
}
Reply
#2

Well because you're not passing any information to the function at all, Pawn can't read minds you know!

pawn Код:
SetTimerEx("DestroySpawnedVehicle", 10000, true, "ii", playerid, vehicleid);
Reply
#3

use a forloop that might only work for id 0.
Reply
#4

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Well because you're not passing any information to the function at all, Pawn can't read minds you know!
Thanks

Will this only work for id 0? (i looked at Lorenc_ poast =/)
Reply
#5

Quote:
Originally Posted by Larsey123IsMe
Посмотреть сообщение
Thanks

Will this only work for id 0? (i looked at Lorenc_ poast =/)
The code I posted will work for any playerid or vehicleid! You must understand that you're getting the playerid and vehicleid passed by the OnPlayerExitVehicle function, and then passing it from the timer to the other function for destroying the vehicle.

If you do not pass that information, the parameters in your vehicle destruction function will not have anything sent to them, therefore they will default to 0.
Reply
#6

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
The code I posted will work for any playerid or vehicleid! You must understand that you're getting the playerid and vehicleid passed by the OnPlayerExitVehicle function, and then passing it from the timer to the other function for destroying the vehicle.

If you do not pass that information, the parameters in your vehicle destruction function will not have anything sent to them, therefore they will default to 0.
oh.. i see Thank You
Reply
#7

Ugh, 10 seconds after i leave the vehicle, then it dont disapiers... =/ what did i do wrong? LoL
Reply
#8

I think i do it on a other way...
How to make a spawn limit for the player? max limit = 5
Vehicles 5 ++ = Error: You have reached the spawn limit. please use: /cleanup.
- /cleanup = Removes the vehicles to the player who use /cleanup

and a admin command, /acleanup == remove all the spawned vehicles

Here is a PART of my code:
pawn Код:
#include <a_samp>

new IsSpawnedVehicle[MAX_PLAYERS];

#define COLOR_ERROR 0xFF303EAA

#define DIALOGID 1

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/vehicles", cmdtext, true, 10) == 0)
    {
        ShowPlayerDialog(playerid, DIALOGID, DIALOG_STYLE_LIST, "Vehicle Categories", "Airplanes\nHelicopters\nBikes\nConvertibles\nIndustrial\nLowriders\nOff Road\nPublic Service Vehicles\nSaloons\nSport Vehicles\nStation Wagons\nBoats\nUnique Vehicles\nRC Vehicles", "Select", "Cancel");
        return 1;
    }

    else if (strcmp("/aclenup", cmdtext, true, 10) == 0) //Fail
    {
        if(IsPlayerAdmin(playerid))
        {
            for(new i = 0; i < MAX_PLAYERS; i++)
            {
                DestroyVehicle(IsSpawnedVehicle[i]);
                SendClientMessage(playerid, 0xFF0000FF, "Info => All vehicles cleaned up!");
                return 1;
            }
        }
        return 0;
    }

    else if (strcmp("/cleanup", cmdtext, true, 10) == 0) //Fail
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            DestroyVehicle(IsSpawnedVehicle[i]);
            SendClientMessage(i, 0xFF0000FF, "Info => You cleaned up the vehicles YOU used/uses");
            IsSpawnedVehicle[i] = 0;
            return 1;
        }
        return 0;
    }
    return 0;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOGID) // Vehicle Dialog
    {
        if(!response) return SendClientMessage(playerid, COLOR_ERROR,"Error: You have cancelled.");
        {
            if(listitem == 0) // Airplanes
            {
                ShowPlayerDialog(playerid, DIALOGID+1, DIALOG_STYLE_LIST, "Airplanes", "Andromada \nAT-400 \nBeagle \nBack", "Select", "Cancel");
                return 1;
            }
        }
    }

    else if(dialogid == DIALOGID+1) // Airplanes
    {
        if(!response) return SendClientMessage(playerid, COLOR_ERROR,"Error: You have cancelled.");
        {
            if(listitem == 0) // Andromada
            {
                new Float:X, Float:Y, Float:Z, Float:A;
                GetPlayerPos(playerid, X,Y,Z);
                GetPlayerFacingAngle(playerid, A);
                new vehicleid = CreateVehicle(592, X,Y,Z,A, -1, -1, -1);
                PutPlayerInVehicle(playerid, vehicleid, 0);
                IsSpawnedVehicle[playerid] = 1;
                return 1;
            }
            else if(listitem == 1) //AT-400
            {
                new Float:X, Float:Y, Float:Z, Float:A;
                GetPlayerPos(playerid, X,Y,Z);
                GetPlayerFacingAngle(playerid, A);
                new vehicleid = CreateVehicle(577, X,Y,Z,A, -1, -1, -1);
                PutPlayerInVehicle(playerid, vehicleid, 0);
                IsSpawnedVehicle[playerid] = 1;
                return 1;
            }
            else if(listitem == 2) // Beagle
            {
                new Float:X, Float:Y, Float:Z, Float:A;
                GetPlayerPos(playerid, X,Y,Z);
                GetPlayerFacingAngle(playerid, A);
                new vehicleid = CreateVehicle(511, X,Y,Z,A, -1, -1, -1);
                PutPlayerInVehicle(playerid, vehicleid, 0);
                IsSpawnedVehicle[playerid] = 1;
                return 1;
            }
            else if(listitem == 3) // Back
            {
                ShowPlayerDialog(playerid, DIALOGID, DIALOG_STYLE_LIST, "Vehicle Categories", "Airplanes", "Select", "Cancel");
                return 1;
            }
        }
    }
    return 0;
}
Reply
#9

for your vehicle like the remove all vehicles u should use

pawn Код:
for(new i = 0; i < MAX_VEHICLES; i++)
            {
instead of

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
            {
Reply
#10

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
for your vehicle like the remove all vehicles u should use

pawn Код:
for(new i = 0; i < MAX_VEHICLES; i++)
            {
instead of

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
            {
Thanks but my commands still dont work like i want it

pawn Код:
else if (strcmp("/acleanup", cmdtext, true, 10) == 0) //Clean up everyones spawned vehicles...
    {
        if(IsPlayerAdmin(playerid))
        {
            for(new i = 0; i < MAX_VEHICLES; i++)
            {
                DestroyVehicle(IsSpawnedVehicle[i] == 1);
                SendClientMessage(playerid, 0xFF0000FF, "Info => Everyones vehicles cleaned up!");
                IsSpawnedVehicle[playerid] = 0;
                return 1;
            }
        }
        return 0;
    }

    else if (strcmp("/cleanup", cmdtext, true, 10) == 0) //The player who type /cleanup, get HIS vehicles cleaned
    {
        for(new i = 0; i < MAX_VEHICLES; i++)
        {
            DestroyVehicle(IsSpawnedVehicle[playerid] == 1);
            SendClientMessage(playerid, 0xFF0000FF, "Info => You cleaned up the vehicles YOU used/uses");
            IsSpawnedVehicle[playerid] = 0;
            return 1;
        }
        return 0;
    }
    return 0;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)