SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 17/07/2017, 06:27 PM   #1
IchNar
Big Clucker
 
Join Date: May 2014
Posts: 55
Reputation: 0
Default MoneyTextdraw

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 is offline   Reply With Quote
Old 17/07/2017, 06:48 PM   #2
IchNar
Big Clucker
 
Join Date: May 2014
Posts: 55
Reputation: 0
Default Re: MoneyTextdraw

Where is problem?? Because that TextDrawString showing only for id 0... or maybe that timer showing only for id 0..
IchNar is offline   Reply With Quote
Old 17/07/2017, 06:49 PM   #3
FailerZ
Huge Clucker
 
FailerZ's Avatar
 
Join Date: Oct 2013
Location: 33.5138 N, 36.2765 E
Posts: 222
Reputation: 21
Default Re: MoneyTextdraw

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
Code:
 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
__________________
[FilterScript]Digital Health & Armour [DHA]
[FilterScript]Labels Creator [LC]
[FilterScript]Debug Mode [D-Mode]
[FilterScript]Advance Fish System [AFS]
FailerZ is offline   Reply With Quote
Old 17/07/2017, 07:03 PM   #4
IchNar
Big Clucker
 
Join Date: May 2014
Posts: 55
Reputation: 0
Default Re: MoneyTextdraw

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
IchNar is offline   Reply With Quote
Old 17/07/2017, 07:14 PM   #5
FailerZ
Huge Clucker
 
FailerZ's Avatar
 
Join Date: Oct 2013
Location: 33.5138 N, 36.2765 E
Posts: 222
Reputation: 21
Default Re: MoneyTextdraw

First, How is this forwarded like this? Where it is getting the playerid? Delete it you are using global timer not player timer
Code:
 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
__________________
[FilterScript]Digital Health & Armour [DHA]
[FilterScript]Labels Creator [LC]
[FilterScript]Debug Mode [D-Mode]
[FilterScript]Advance Fish System [AFS]
FailerZ is offline   Reply With Quote
Old 17/07/2017, 08:52 PM   #6
Arthur Kane
Gangsta
 
Join Date: Sep 2012
Location: California
Posts: 737
Reputation: 63
Default Re: MoneyTextdraw

PHP Code:
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 Code:
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.

PHP Code:
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.
Arthur Kane is online now   Reply With Quote
Old 17/07/2017, 09:13 PM   #7
Pottus
Godfather
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 5,274
Reputation: 1141
Default Re: MoneyTextdraw

Quote:
Originally Posted by FailerZ View Post
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!
Pottus is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 06:09 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.