About 3DTextLabel and Timers
#1

Hey guys, so I decided to build shell system by using OnPlayerWeaponShot, so I got in trouble that I wanted to make the 3dtextlabel disappear after some of time but I get an errors everytime trying to put a timer, someone can tell me how I can make all those to disappear after like 5minutes with timer?

PHP код:
public OnPlayerWeaponShot(playeridweaponidhittypehitidFloat:fXFloat:fYFloat:fZ)
{
    new 
Float:XFloat:YFloat:Z;
    
GetPlayerPos(playeridXYZ);
    if(
weaponid == 24)
    {
        
Create3DTextLabel("Desert Eagle Shell"COLOR_GREYXYZ30.000);
    }
    if(
weaponid == 31)
    {
        
Create3DTextLabel("M416 Assult rifle Shell"COLOR_GREYXYZ30.000);
    }
    if(
weaponid == 30)
    {
        
Create3DTextLabel("AK-47 Assult rifle Shell"COLOR_GREYXYZ30.000);
    }
    if(
weaponid == 22)
    {
        
Create3DTextLabel("9MM Pistol Shell"COLOR_GREYXYZ30.000);
    }
    if(
weaponid == 23)
    {
    
Create3DTextLabel("9MM Silencer Shell"COLOR_GREYXYZ30.000);
    }
    if(
weaponid == 25)
    {
    
Create3DTextLabel("Remington ShotGun Shell"COLOR_GREYXYZ30.000);
    }
    if(
weaponid == 28)
    {
    
Create3DTextLabel("UZI SMG Shell"COLOR_GREYXYZ30.000);
    }
    if(
weaponid == 29)
    {
    
Create3DTextLabel("MP5 SMG Shell"COLOR_GREYXYZ30.000);
    }
    if(
weaponid == 32)
    {
    
Create3DTextLabel("TEC9 SMG Shell"COLOR_GREYXYZ30.000);
    }
    if(
weaponid == 33)
    {
    
Create3DTextLabel("Contry Rifle Shell"COLOR_GREYXYZ30.000);
    }
    if(
weaponid == 34)
    {
    
Create3DTextLabel("Sniper Rifle Shell"COLOR_GREYXYZ30.000);
    }
    return 
true;

Reply
#2

Well, what you should do:
pawn Код:
#define MAX_SHELLS 1000 //Or whatever you want the maximum to be.
#define ShellDespawnTime 300000 //Currently 5 minutes, set it to what you want it.

new Text3D:Shell[MAX_SHELLS]; //So each shell has it's own 3DTextLabel.
new ExistentShells; //In order to know which shell is which.
new ShellDespawnTimer[MAX_SHELLS]; //A timer for each shell to despawn
new shellid; //A variable to define shell ID's (used for the timers)

public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    if(weaponid != 24 && weaponid!= 31 && weaponid !=30 && weaponid !=22 && weaponid != 23 && weaponid != 25 && weaponid != 28 && weaponid != 29 && weaponid != 32 && weaponid != 33 && weaponid != 34) return 0; //Making sure only the weapons below create shells (add add onto the variable "ExistentShells"
    ExistentShells++; //Showing how many existent shells there are in order to establish a shell ID
    switch(weaponid)
    {
        case 24: Shell[ExistentShells] = Create3DTextLabel("Desert Eagle Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 31: Shell[ExistentShells] = Create3DTextLabel("M416 Assult rifle Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 30: Shell[ExistentShells] = Create3DTextLabel("AK-47 Assult rifle Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 22: Shell[ExistentShells] = Create3DTextLabel("9MM Pistol Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 23: Shell[ExistentShells] = Create3DTextLabel("9MM Silencer Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 25: Shell[ExistentShells] = Create3DTextLabel("Remington ShotGun Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 28: Shell[ExistentShells] = Create3DTextLabel("UZI SMG Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 29: Shell[ExistentShells] = Create3DTextLabel("MP5 SMG Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 32: Shell[ExistentShells] = Create3DTextLabel("TEC9 SMG Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 33: Shell[ExistentShells] = Create3DTextLabel("Contry Rifle Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 34: Shell[ExistentShells] = Create3DTextLabel("Sniper Rifle Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
    }
    shellid = ExistentShells;
    ShellDespawnTimer[shellid] = SetTimerEx("ShellDespawn", ShellDespawnTime, false, "i", shellid);
    return 1;
}

forward ShellDespawn(shellid);
public ShellDespawn(shellid)
{
    Delete3DTextLabel(Shell[shellid]);
    return 1;
}
Lemme know if there are any bugs. This is untested and I just wrote the code here, in ****** Chrome.
Reply
#3

Quote:
Originally Posted by nmader
Посмотреть сообщение
Well, what you should do:
pawn Код:
#define MAX_SHELLS 1000 //Or whatever you want the maximum to be.
#define ShellDespawnTime 300000 //Currently 5 minutes, set it to what you want it.

new Text3D:Shell[MAX_SHELLS]; //So each shell has it's own 3DTextLabel.
new ExistentShells; //In order to know which shell is which.
new ShellDespawnTimer[MAX_SHELLS]; //A timer for each shell to despawn
new shellid; //A variable to define shell ID's (used for the timers)

public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    if(weaponid != 24 && weaponid!= 31 && weaponid !=30 && weaponid !=22 && weaponid != 23 && weaponid != 25 && weaponid != 28 && weaponid != 29 && weaponid != 32 && weaponid != 33 && weaponid != 34) return 0; //Making sure only the weapons below create shells (add add onto the variable "ExistentShells"
    ExistentShells++; //Showing how many existent shells there are in order to establish a shell ID
    switch(weaponid)
    {
        case 24: Shell[ExistentShells] = Create3DTextLabel("Desert Eagle Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 31: Shell[ExistentShells] = Create3DTextLabel("M416 Assult rifle Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 30: Shell[ExistentShells] = Create3DTextLabel("AK-47 Assult rifle Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 22: Shell[ExistentShells] = Create3DTextLabel("9MM Pistol Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 23: Shell[ExistentShells] = Create3DTextLabel("9MM Silencer Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 25: Shell[ExistentShells] = Create3DTextLabel("Remington ShotGun Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 28: Shell[ExistentShells] = Create3DTextLabel("UZI SMG Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 29: Shell[ExistentShells] = Create3DTextLabel("MP5 SMG Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 32: Shell[ExistentShells] = Create3DTextLabel("TEC9 SMG Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 33: Shell[ExistentShells] = Create3DTextLabel("Contry Rifle Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
        case 34: Shell[ExistentShells] = Create3DTextLabel("Sniper Rifle Shell", COLOR_GREY, X, Y, Z, 30.0, 0, 0);
    }
    shellid = ExistentShells;
    ShellDespawnTimer[shellid] = SetTimerEx("ShellDespawn", ShellDespawnTime, false, "i", shellid);
    return 1;
}

forward ShellDespawn(shellid);
public ShellDespawn(shellid)
{
    Delete3DTextLabel(Shell[shellid]);
    return 1;
}
Lemme know if there are any bugs. This is untested and I just wrote the code here, in ****** Chrome.
Here is a warning I got
Quote:

warning 219: local variable "shellid" shadows a variable at a preceding level
the line : public ShellDespawn(shellid)

Reply
#4

Delete:
pawn Код:
new shellid;
At the top of the script. Other then that have you tested it?
Reply
#5

Quote:
Originally Posted by nmader
Посмотреть сообщение
Delete:
pawn Код:
new shellid;
At the top of the script. Other then that have you tested it?
Thank you, works fine! +rep'ed.
Reply
#6

Quote:
Originally Posted by DemME
Посмотреть сообщение
Thank you, works fine! +rep'ed.
Glad to hear it! I surprise myself sometimes.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)