Menubox
#1

Hello!

There is some wrong with a texdraw/menubox for a script.

Uhm... when i use this code below, other players "steal" the menu from all others, if you are in a vehicle and have the menu on screen, you loose it when some one else enter a vehicle
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
                vmid[playerid] = GetVehicleStatID(GetVehicleModel(vehicleid));
        if(vmid[playerid] > -1) {
                        bptype[playerid] = 0;
                        #if(USE_TEXTDRAWS)
                            TextDrawHideForPlayer(playerid, bombtext[playerid]);
                            TextDrawDestroy(bombtext[playerid]);
                            KillTimer(removetimer[playerid]);
                                SetTimerEx("ShowTextDraw", 500, 0, "iii", playerid, vehicleid, 0);
                        #endif
                }
                return 1;
}
Mauzen
And if i remove this part, the menu are not being "stealed" but it disappear after you been playing for a while. like 5-15 min, and if you get out the vehicle and enter it again, the menu appears 2 sec and disappear again. then i have to restart server to get it work proper again
pawn Код:
TextDrawHideForPlayer(playerid, bombtext[playerid]);
TextDrawDestroy(bombtext[playerid]);
KillTimer(removetimer[playerid]);
Reply
#2

How do you show the textdraw?
Reply
#3

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
How do you show the textdraw?
Like this
pawn Код:
#define USE_TEXTDRAWS 1
forward RemoveTextDraw(playerid);
forward ShowTextDraw(playerid, vehicleid, count);

#if(USE_TEXTDRAWS)

public ShowTextDraw(playerid, vehicleid, count)
{
        if(IsPlayerInVehicle(playerid, vehicleid)) {
            bombtext[playerid] = TextDrawCreate(480, 200, " ");                
            TextDrawUseBox(bombtext[playerid], 1);
            TextDrawBoxColor(bombtext[playerid], 0x00000066);
            TextDrawFont(bombtext[playerid], 1);
            UpdateTextDraw(playerid);
            removetimer[playerid] = SetTimerEx("RemoveTextDraw", 2000, 1, "i", playerid);
            TextDrawShowForPlayer(playerid, bombtext[playerid]);
        } else {
            count ++;
            if(count < 20) SetTimerEx("ShowTextDraw", 500, 0, "iii", playerid, vehicleid, count);
        }
}
public RemoveTextDraw(playerid)
{
        if(!IsPlayerInAnyVehicle(playerid)) {
            TextDrawHideForPlayer(playerid, bombtext[playerid]);
            TextDrawDestroy(bombtext[playerid]);
            KillTimer(removetimer[playerid]);
        }
}
stock UpdateTextDraw(playerid)
{
        new text[160] = " ";
        #if(USE_TEXTDRAWS == 1)
            if(bptype[playerid] == 0) text = "~r~Nothing~w~";
                else text = "Nothing";
            for(new i = 1; i < sizeof gBombTypes; i ++)
                if(gVehicleBombs[vmid[playerid]][i + 1] == 1) {
                    if(bptype[playerid] == i) {
                        if(bfree[playerid] || !IsPlayerAllowedToDropBomb(playerid)) format(text, 160, "%s~n~~r~%s~w~", text, gBombTypes[i][bombName]);
                            else format(text, 160, "%s~n~~g~%s~w~", text, gBombTypes[i][bombName]);
                    } else format(text, 160, "%s~n~%s", text, gBombTypes[i][bombName]);
                }
        #elseif(USE_TEXTDRAWS == 2)
            if(bfree[playerid] || bptype[playerid] == 0 || !IsPlayerAllowedToDropBomb(playerid)) format(text, 160, "~r~%s", gBombTypes[bptype[playerid]][bombName]);
                else format(text, 160, "~g~%s", gBombTypes[bptype[playerid]][bombName]);
        #endif
        TextDrawSetString(bombtext[playerid], text);
}
Reply
#4

Create/Destroy the textdraw when player connects/disconnects

OnPlayerConnect:
pawn Код:
bombtext[playerid] = TextDrawCreate(480, 200, " ");                
TextDrawUseBox(bombtext[playerid], 1);
TextDrawBoxColor(bombtext[playerid], 0x00000066);
TextDrawFont(bombtext[playerid], 1);
OnPlayerDisconnect:
pawn Код:
TextDrawDestroy(bombtext[playerid]);
pawn Код:
public ShowTextDraw(playerid, vehicleid, count)
{
        if(IsPlayerInVehicle(playerid, vehicleid)) {
            UpdateTextDraw(playerid);
            removetimer[playerid] = SetTimerEx("RemoveTextDraw", 2000, 1, "i", playerid);
            TextDrawShowForPlayer(playerid, bombtext[playerid]);
        } else {
            count ++;
            if(count < 20) SetTimerEx("ShowTextDraw", 500, 0, "iii", playerid, vehicleid, count);
        }
}

public RemoveTextDraw(playerid)
{
        if(!IsPlayerInAnyVehicle(playerid)) {
            TextDrawHideForPlayer(playerid, bombtext[playerid]);
            KillTimer(removetimer[playerid]);
        }
}
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
        vmid[playerid] = GetVehicleStatID(GetVehicleModel(vehicleid));
        if(vmid[playerid] > -1) {
                        bptype[playerid] = 0;
                        #if(USE_TEXTDRAWS)
                            TextDrawHideForPlayer(playerid, bombtext[playerid]);
                            KillTimer(removetimer[playerid]);
                            SetTimerEx("ShowTextDraw", 500, 0, "iii", playerid, vehicleid, 0);
                        #endif
                }
                return 1;
}
Reply
#5

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
Create/Destroy the textdraw when player connects/disconnects

OnPlayerConnect:
pawn Код:
bombtext[playerid] = TextDrawCreate(480, 200, " ");                
TextDrawUseBox(bombtext[playerid], 1);
TextDrawBoxColor(bombtext[playerid], 0x00000066);
TextDrawFont(bombtext[playerid], 1);
OnPlayerDisconnect:
pawn Код:
TextDrawDestroy(bombtext[playerid]);
pawn Код:
public ShowTextDraw(playerid, vehicleid, count)
{
        if(IsPlayerInVehicle(playerid, vehicleid)) {
            UpdateTextDraw(playerid);
            removetimer[playerid] = SetTimerEx("RemoveTextDraw", 2000, 1, "i", playerid);
            TextDrawShowForPlayer(playerid, bombtext[playerid]);
        } else {
            count ++;
            if(count < 20) SetTimerEx("ShowTextDraw", 500, 0, "iii", playerid, vehicleid, count);
        }
}

public RemoveTextDraw(playerid)
{
        if(!IsPlayerInAnyVehicle(playerid)) {
            TextDrawHideForPlayer(playerid, bombtext[playerid]);
            KillTimer(removetimer[playerid]);
        }
}
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
        vmid[playerid] = GetVehicleStatID(GetVehicleModel(vehicleid));
        if(vmid[playerid] > -1) {
                        bptype[playerid] = 0;
                        #if(USE_TEXTDRAWS)
                            TextDrawHideForPlayer(playerid, bombtext[playerid]);
                            KillTimer(removetimer[playerid]);
                            SetTimerEx("ShowTextDraw", 500, 0, "iii", playerid, vehicleid, 0);
                        #endif
                }
                return 1;
}
This is a FS, should i add OnPlayerConnect and OnPlayerDisconnect to it?
Reply
#6

Quote:
Originally Posted by cruising
Посмотреть сообщение
This is a FS, should i add OnPlayerConnect and OnPlayerDisconnect to it?
OnPlayerConnect doesn't work well in FS.

Use OnFilterScriptInit and OnFilterScriptExit instead.

OnFilterScriptInit:
pawn Код:
for(new i=0; i < MAX_PLAYERS; i++)
{
    bombtext[i] = TextDrawCreate(480, 200, " ");                
    TextDrawUseBox(bombtext[i], 1);
    TextDrawBoxColor(bombtext[i], 0x00000066);
    TextDrawFont(bombtext[i], 1);
}
OnFilterScriptExit:
pawn Код:
for(new i=0; i < MAX_PLAYERS; i++)
{
    TextDrawDestroy(bombtext[i]);
}
Reply
#7

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
OnPlayerConnect doesn't work well in FS.

Use OnFilterScriptInit and OnFilterScriptExit instead.

OnFilterScriptInit:
pawn Код:
for(new i=0; i < MAX_PLAYERS; i++)
{
    bombtext[i] = TextDrawCreate(480, 200, " ");                
    TextDrawUseBox(bombtext[i], 1);
    TextDrawBoxColor(bombtext[i], 0x00000066);
    TextDrawFont(bombtext[i], 1);
}
OnFilterScriptExit:
pawn Код:
for(new i=0; i < MAX_PLAYERS; i++)
{
    TextDrawDestroy(bombtext[i]);
}
I just baked the FS in to my GM, and im gonna try the first tip you told, getting back with info soon.
Reply
#8

It seams the menu works like it should do now. But when i restart the server, and enter a vehicle the menu is gone, until i close and start the server again.

it seams that the speedo script i use make the problem, bc when i change in menu in game with the buttons, i see the menu comes like a text only were the speedo is, it is like the menu is behind the speedo textdraw as a text and not a box menu and only shows when i push the button.

Maybe there is some bug in the speedo script who crash the menu? i mean, you should be able to have 2 texdraws that not "take over" the other one?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)