PDA

View Full Version : MoneyTextdraw


IchNar
17/07/2017, 06:27 PM
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;
}

IchNar
17/07/2017, 06:48 PM
Where is problem?? Because that TextDrawString showing only for id 0... or maybe that timer showing only for id 0..

FailerZ
17/07/2017, 06:49 PM
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

IchNar
17/07/2017, 07:03 PM
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

FailerZ
17/07/2017, 07:14 PM
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

Kane
17/07/2017, 08:52 PM
new moneyTimer[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
for(new i = 0; i < 3; i++)
{
PlayerTextDrawShow(playerid,TDEditor_PTD[playerid][i]);
}
moneyTimer[playerid] = SetTimerEx("MoneyUpdater", 1000, true, "i", playerid);

return 1;
}


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.

http://wiki.sa-mp.com/wiki/SetTimerEx
http://wiki.sa-mp.com/wiki/SetTimer

Specifically what you should learn about.

public MoneyUpdater(playerid)
{
new
string[60];

format(string, sizeof(string), "%.2f", Peniaze[playerid]);
PlayerTextDrawSetString(playerid, TDEditor_PTD[playerid][1], string);
return 1;
}


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

Pottus
17/07/2017, 09:13 PM
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!