SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 28/05/2020, 07:37 PM   #1
Hazon
Huge Clucker
 
Hazon's Avatar
 
Join Date: May 2018
Location: Who cares ?
Posts: 200
Reputation: 37
Default Code.

This code use one textdraw to show player speed and fuel, I made two textdraws and one is for fuel and other for speed, so how to make code separate ?

Code is in OnPlayerStateChange

Code:
new string[64];
			if (!DoesVehicleModelTakeFuel(tvar2) || iseventvehicle[tvar1] != 0 || IsSchoolVehicle(tvar1) != 0/* || IsRPSchoolVehicle(tvar1)*/ || ptruckstats[playerid][0] == tvar1 || pbusstats[playerid][0] == tvar1 || pfarmstats[playerid][0] == tvar1 || cfs[tvar1][0] == 2) {
				if (tvar2 == 449) {
					if (tvar1 == tram1) {
						Update3DTextLabelText(tram1text, 0xFFFFFF00, "Hold F / Enter & press G");
					}
					else {

					}
				}
    			format(string, 64, "~p~Speed: ~w~%c~n~~b~Fuel: ~w~N/A", '0');
			}
			else if (floatround(Gas[tvar1]) > 10) {
   					format(string, 64, "~p~Speed: ~w~%c~n~~b~Fuel: ~w~%d%", '0', floatround(Gas[tvar1]));
			}
			else {
    				format(string, 64, "~p~Speed: ~w~%c~n~~b~Fuel: ~r~%d%", '0', floatround(Gas[tvar1]));
			}
   				if (hudText[playerid] == PlayerText:-1) {
				hudText[playerid] = CreatePlayerTextDraw(playerid, 530.0, 340.5, string);
				PlayerTextDrawLetterSize(playerid, hudText[playerid], 0.5, 1.6);
				PlayerTextDrawSetProportional(playerid, hudText[playerid], 1);
				PlayerTextDrawSetOutline(playerid, hudText[playerid], 1);
			}
			else {
				PlayerTextDrawSetString(playerid, hudText[playerid], string);
			}
		}
Hazon is offline   Reply With Quote
Old 29/05/2020, 08:58 AM   #2
Hazon
Huge Clucker
 
Hazon's Avatar
 
Join Date: May 2018
Location: Who cares ?
Posts: 200
Reputation: 37
Default Re: Code.

Bump!
Hazon is offline   Reply With Quote
Old 29/05/2020, 09:03 AM   #3
SharpenBlade
Big Clucker
 
Join Date: May 2020
Posts: 169
Reputation: 21
Default Re: Code.

You can split the message in two.
PHP Code:
format(string64"~p~Speed: ~w~%c"'0');
format(string164"~b~Fuel: ~w~N/A"); 
After that you just set the string to the textdraw.
PHP Code:
PlayerTextDrawSetString(playeridSpeedTextdrawstring);
PlayerTextDrawSetString(playeridFuelTextdrawstring1); 
Is the same for any other cases(I saw you have more strings formated there related to fuel and speed).

This is the entire code:
PHP Code:
new string[64], string1[64];
    if (!
DoesVehicleModelTakeFuel(tvar2) || iseventvehicle[tvar1] != || IsSchoolVehicle(tvar1) != 0/* || IsRPSchoolVehicle(tvar1)*/ || ptruckstats[playerid][0] == tvar1 || pbusstats[playerid][0] == tvar1 || pfarmstats[playerid][0] == tvar1 || cfs[tvar1][0] == 2) {
        if (
tvar2 == 449) {
            if (
tvar1 == tram1) {
                
Update3DTextLabelText(tram1text0xFFFFFF00"Hold F / Enter & press G");
            }
            else {

            }
        }
        
format(string64"~p~Speed: ~w~%c"'0');
        
format(string164"~b~Fuel: ~w~N/A"); 
    }
    else if (
floatround(Gas[tvar1]) > 10) {
                
format(string64"~p~Speed: ~w~%c"'0');
                
format(string164"~b~Fuel: ~w~%d"floatround(Gas[tvar1])); 
    }
    else {
            
format(string64"~p~Speed: ~w~%c"'0');
            
format(string164"~b~Fuel: ~r~%d"floatround(Gas[tvar1])); 
    }
    if (
hudText[playerid] == PlayerText:-1) {
        
hudText[playerid] = CreatePlayerTextDraw(playerid530.0340.5string);
        
PlayerTextDrawLetterSize(playeridhudText[playerid], 0.51.6);
        
PlayerTextDrawSetProportional(playeridhudText[playerid], 1);
        
PlayerTextDrawSetOutline(playeridhudText[playerid], 1);
    }
    else {
        
PlayerTextDrawSetString(playeridhudText[playerid], string);
    } 
SharpenBlade is offline   Reply With Quote
Old 29/05/2020, 09:16 AM   #4
Variable™
Gangsta
 
Variable™'s Avatar
 
Join Date: Jul 2015
Posts: 823
Reputation: 200
Default Re: Code.

Quote:
Originally Posted by SharpenBlade View Post
You can split the message in two.
PHP Code:
format(string64"~p~Speed: ~w~%c"'0');
format(string164"~b~Fuel: ~w~N/A"); 
After that you just set the string to the textdraw.
PHP Code:
PlayerTextDrawSetString(playeridSpeedTextdrawstring);
PlayerTextDrawSetString(playeridFuelTextdrawstring1); 
Is the same for any other cases(I saw you have more strings formated there related to fuel and speed).

This is the entire code:
PHP Code:
new string[64], string1[64];
    if (!
DoesVehicleModelTakeFuel(tvar2) || iseventvehicle[tvar1] != || IsSchoolVehicle(tvar1) != 0/* || IsRPSchoolVehicle(tvar1)*/ || ptruckstats[playerid][0] == tvar1 || pbusstats[playerid][0] == tvar1 || pfarmstats[playerid][0] == tvar1 || cfs[tvar1][0] == 2) {
        if (
tvar2 == 449) {
            if (
tvar1 == tram1) {
                
Update3DTextLabelText(tram1text0xFFFFFF00"Hold F / Enter & press G");
            }
            else {

            }
        }
        
format(string64"~p~Speed: ~w~%c"'0');
        
format(string164"~b~Fuel: ~w~N/A"); 
    }
    else if (
floatround(Gas[tvar1]) > 10) {
                
format(string64"~p~Speed: ~w~%c"'0');
                
format(string164"~b~Fuel: ~w~%d"floatround(Gas[tvar1])); 
    }
    else {
            
format(string64"~p~Speed: ~w~%c"'0');
            
format(string164"~b~Fuel: ~r~%d"floatround(Gas[tvar1])); 
    }
    if (
hudText[playerid] == PlayerText:-1) {
        
hudText[playerid] = CreatePlayerTextDraw(playerid530.0340.5string);
        
PlayerTextDrawLetterSize(playeridhudText[playerid], 0.51.6);
        
PlayerTextDrawSetProportional(playeridhudText[playerid], 1);
        
PlayerTextDrawSetOutline(playeridhudText[playerid], 1);
    }
    else {
        
PlayerTextDrawSetString(playeridhudText[playerid], string);
    } 
No...

Here's an idea
Code:
    new string[15];
    format(string, sizeof(string), "something"); //somewhere
    format(string, sizeof(string), "%s else", string); //somewhere else
__________________
Need a game server? Contact me for information.
Variable™ is offline   Reply With Quote
Old 29/05/2020, 09:18 AM   #5
SharpenBlade
Big Clucker
 
Join Date: May 2020
Posts: 169
Reputation: 21
Default Re: Code.

Quote:
Originally Posted by Variable™ View Post
No...

Here's an idea
Code:
    new string[15];
    format(string, sizeof(string), "something"); //somewhere
    format(string, sizeof(string), "%s else", string); //somewhere else
He has 2 textdraws, what you wrote suits for 1 textdraw.
SharpenBlade is offline   Reply With Quote
Old 29/05/2020, 09:21 AM   #6
Variable™
Gangsta
 
Variable™'s Avatar
 
Join Date: Jul 2015
Posts: 823
Reputation: 200
Default Re: Code.

Quote:
Originally Posted by SharpenBlade View Post
He has 2 textdraws, what you wrote suits for 1 textdraw.
Ah alright I didn't read the question, you can still use the same trick though. Instead of creating two strings, use one and format it to what you want first, then set it as the textdraw string, then re-format it, and set it as a textdraw string for the other textdraw. If you know what I mean.
__________________
Need a game server? Contact me for information.
Variable™ 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[solved]Converting my old Mysql code to new mysql code.. Darrenr Scripting Help 1 22/03/2015 03:05 PM
some help with a code jimis Scripting Help 2 21/05/2014 12:02 PM
How to make when using pawno and type part of the code, to show the full code ? bustern Scripting Help 10 28/08/2013 09:10 AM
[Tool/Web/Other] Code Highlighter - Highlight code to find brackets, organize code, ... Sinner Tools and Files 8 09/03/2012 01:28 PM
Get ride of wepons on Spawn code | need code cssbart Help Archive 5 19/04/2010 06:05 PM


All times are GMT. The time now is 07:04 AM.


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