MoneyTextdraw
#1

Greedings,i have big problem...This textdraw update only for ID 0 but not for ID 1.Please help me.
//OnGamemodeInit creating the textdraw
for(new i; i<MAX_PLAYERS; i++)
{
TDEditor_PTD[i][0] = CreatePlayerTextDraw(i, 494.000152, 80.239952, "box");
PlayerTextDrawLetterSize(i, TDEditor_PTD[i][0], 0.000000, 1.840005);
PlayerTextDrawTextSize(i, TDEditor_PTD[i][0], 612.000000, 0.000000);
PlayerTextDrawAlignment(i, TDEditor_PTD[i][0], 1);
PlayerTextDrawColor(i, TDEditor_PTD[i][0], -1);
PlayerTextDrawUseBox(i, TDEditor_PTD[i][0], 1);
PlayerTextDrawBoxColor(i, TDEditor_PTD[i][0], 255);
PlayerTextDrawSetShadow(i, TDEditor_PTD[i][0], 0);
PlayerTextDrawSetOutline(i, TDEditor_PTD[i][0], 0);
PlayerTextDrawBackgroundColor(i, TDEditor_PTD[i][0], 255);
PlayerTextDrawFont(i, TDEditor_PTD[i][0], 1);
PlayerTextDrawSetProportional(i, TDEditor_PTD[i][0], 1);
PlayerTextDrawSetShadow(i, TDEditor_PTD[i][0], 0);

TDEditor_PTD[i][1] = CreatePlayerTextDraw(i, 490.800170, 80.239982, "2500000.596");
PlayerTextDrawLetterSize(i, TDEditor_PTD[i][1], 0.320799, 1.592533);
PlayerTextDrawAlignment(i, TDEditor_PTD[i][1], 1);
PlayerTextDrawColor(i, TDEditor_PTD[i][1], 8388863);
PlayerTextDrawSetShadow(i, TDEditor_PTD[i][1], 0);
PlayerTextDrawSetOutline(i, TDEditor_PTD[i][1], 0);
PlayerTextDrawBackgroundColor(i, TDEditor_PTD[i][1], 255);
PlayerTextDrawFont(i, TDEditor_PTD[i][1], 1);
PlayerTextDrawSetProportional(i, TDEditor_PTD[i][1], 1);
PlayerTextDrawSetShadow(i, TDEditor_PTD[i][1], 0);

TDEditor_PTD[i][2] = CreatePlayerTextDraw(i, 570.799804, 79.493301, "Eur");
PlayerTextDrawLetterSize(i, TDEditor_PTD[i][2], 0.504000, 1.689600);
PlayerTextDrawAlignment(i, TDEditor_PTD[i][2], 1);
PlayerTextDrawColor(i, TDEditor_PTD[i][2], 8388863);
PlayerTextDrawSetShadow(i, TDEditor_PTD[i][2], 0);
PlayerTextDrawSetOutline(i, TDEditor_PTD[i][2], 0);
PlayerTextDrawBackgroundColor(i, TDEditor_PTD[i][2], 255);
PlayerTextDrawFont(i, TDEditor_PTD[i][2], 1);
PlayerTextDrawSetProportional(i, TDEditor_PTD[i][2], 1);
PlayerTextDrawSetShadow(i, TDEditor_PTD[i][2], 0);
}
//OnPlayerConnect
PlayerTextDrawShow(playerid,TDEditor_PTD[playerid][0]);
PlayerTextDrawShow(playerid,TDEditor_PTD[playerid][1]);
PlayerTextDrawShow(playerid,TDEditor_PTD[playerid][2]);
SetTimer("MoneyUpdater",1,true);
//public
public MoneyUpdater(playerid)
{
for(new i; i<MAX_PLAYERS; i++)
{
new string[128];
format(string,sizeof(string),"%.2f", Peniaze[i]);
PlayerTextDrawSetString(i,TDEditor_PTD[i][1],string);
}
return 1;
}
Reply
#2

Where is problem?? Because that TextDrawString showing only for id 0... or maybe that timer showing only for id 0..
Reply
#3

Why are you creating the player textdraws OnGameModeInit? They won't be created for all the players..
Create them under OnPlayerConnect and destroy them OnPlayerDisconnect and get rid of that loop

EDIT: and hold on
Код:
 SetTimer("MoneyUpdater",1,true);
I am surprised you are not facing lag with that!? You are repeating a timer every 1ms!! Change it to 1000ms. one second is enough. Or no need for that timer even. Just update the textdraw whenever its value has changed
Reply
#4

It still doesnt work the string work only for ID 0 i gave Money to my friend (he had ID 1)and he still have the default textdraw 2500000 but he gave Money to me and i had ID 0 and it worked perfectly but only for ID 0 i dont know where is problem
Reply
#5

First, How is this forwarded like this? Where it is getting the playerid? Delete it you are using global timer not player timer
Код:
 public MoneyUpdater(playerid)
{
	for(new i; i<MAX_PLAYERS; i++)
	{
		new string[128];
		format(string,sizeof(string),"%.2f", Peniaze[i]);
		PlayerTextDrawSetString(i,TDEditor_PTD[i][1],string);
	}
}
Second, Show the codes of the command you are using to give money.

Also make sure you have restarted the server correctly (rcon exit) then open and connect to it after you fixed the textdraws so they are created correctly when the player connect.

EDIT: And another flaw, Move the timer to OnGameModeInit
Reply
#6

PHP код:
new moneyTimer[MAX_PLAYERS];
public 
OnPlayerConnect(playerid)
{
    for(new 
03i++)
    {
         
PlayerTextDrawShow(playerid,TDEditor_PTD[playerid][i]);
    }
    
moneyTimer[playerid] = SetTimerEx("MoneyUpdater"1000true"i"playerid);
    return 
1;

PHP код:
public OnPlayerDisconnect(playerid)
{
   
KillTimer(moneyTimer[playerid]);
   return 
1;

We can just create a loop to show the textdraw just to be more convenient and clean.

You need to use SetTimerEx to have a way to use the playerid inside the function.

https://sampwiki.blast.hk/wiki/SetTimerEx
https://sampwiki.blast.hk/wiki/SetTimer

Specifically what you should learn about.

PHP код:
public MoneyUpdater(playerid)
{
    new 
          
string[60];
    
format(stringsizeof(string), "%.2f"Peniaze[playerid]);
    
PlayerTextDrawSetString(playeridTDEditor_PTD[playerid][1], string);
    return 
1;

I recommend not using a timer and just updating the textdraw when a player receives / loses money.
Reply
#7

Quote:
Originally Posted by FailerZ
Посмотреть сообщение
Create them under OnPlayerConnect and destroy them OnPlayerDisconnect and get rid of that loop
The best way is to ONLY create Player TD's when a player successfully logs in!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)