[Tutorial] YSI: Examples for loading an XML file with y_td - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (
https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] YSI: Examples for loading an XML file with y_td (
/showthread.php?tid=421433)
YSI: Examples for loading an XML file with y_td -
Finn - 09.03.2013
Make sure you use fixed
y_td:
http://forum.sa-mp.com/showthread.ph...65#post2419465
Here's an example of an XML file which contains 2 styles and under the example there's descriptions for each property.
Edit: edited the example
Code:
<XML>
<textdraw name="TEXT">
<x>100.0</x>
<y>100.0</y>
<letterx>1.0</letterx>
<lettery>1.0</lettery>
<textx>0.0</textx>
<texty>999.0</texty>
<alignment>left</alignment>
<color>0xFFFFFFFF</color>
<box>0xFFFFFFFF</box>
<shadow>0</shadow>
<outline>0</outline>
<background>0x000000FF</background>
<font>1</font>
<proportional>1</proportional>
<time>0</time>
</textdraw>
<textdraw name="TEXT2">
<x>100.0</x>
<y>200.0</y>
<letterx>1.0</letterx>
<lettery>1.0</lettery>
<textx>0.0</textx>
<texty>999.0</texty>
<alignment>left</alignment>
<color>0xFFFFFFFF</color>
<box>0x000000FF</box>
<shadow>0</shadow>
<outline>0</outline>
<background>0x000000FF</background>
<font>1</font>
<proportional>1</proportional>
<time>0</time>
</textdraw>
</XML>
name | String: name of the style (important) |
- | - |
x | Float: x-coordinate |
y | Float: y-coordinate |
letterx | Float: horizontal letter size |
lettery | Float: vertical letter size |
textx | Float: horizontal text size |
texty | Float: vertical text size |
alignment | left, right or center |
colour/color | Hex: color |
box | Hex: box color (don't include this to set it off) |
shadow | Int: shadow value (0 = no shadow) |
outline | Int: outline value (0 = no outline) |
background | Hex: background color |
font | Int: font type |
proportional | toggle proportional (don't include this to set it off) |
time | Int: time how long the text draw will be displayed (in ms) |
Here's an example how you load the XML file:
Code:
public OnGameModeInit()
{
TD_Parse("example_directory/xml_file.xml");
return 1;
}
Here's an example how you can show a styled text draw to a player:
Code:
public OnPlayerSpawn(playerid)
{
new Style:styleid = TD_GetNamed("TEXT");
new Text:textdrawid = TD_Display("Hello World", styleid);
TD_ShowForPlayer(playerid, textdrawid);
return 1;
}
Here's a full script which creates a text draw which changes color every second after player has spawned. I'm using the XML file shown on the top of the post.
pawn Code:
#include <a_samp>
#include <YSI\y_master>
#include <YSI\y_timers>
#include <YSI\y_td>
main() { }
new Text:td_pHelloWorld[MAX_PLAYERS];
// This function is just a wrapper for clean usage of the player-draws
stock td_Show(playerid, Text:textdrawid, Style:styleid, text[])
{
if(textdrawid != Text:INVALID_TEXT_DRAW)
{
// If the draw already exists, just set the content
TD_SetString(textdrawid, text);
}
else
{
// If the draw doesn't exist, create it
textdrawid = TD_Display(text, styleid);
}
// Show the draw
return TD_ShowForPlayer(playerid, textdrawid);
}
public OnGameModeInit()
{
// Parse the XML file
TD_Parse("example/example.xml");
// This is a must for a working gamemode, taken from some default script
AddPlayerClass(265,1958.3783,1343.1572,15.3746,270.1425,0,0,0,0,-1,-1);
return 1;
}
public OnPlayerSpawn(playerid)
{
// Format the content of the text draw "Hello <player name>"
new string[64];
GetPlayerName(playerid, string, sizeof(string));
format(string, sizeof(string), "Hello %s", string);
// Show the text draw to the player using style "TEXT"
td_Show(playerid, td_pHelloWorld[playerid], TD_GetNamed("TEXT"), string);
return 1;
}
public OnPlayerConnect(playerid)
{
// If the draw is active and a new player comes in -> remove the draw and set it invalid
if(td_pHelloWorld[playerid] != Text:INVALID_TEXT_DRAW)
{
TD_Destroy(td_pHelloWorld[playerid]);
td_pHelloWorld[playerid] = Text:INVALID_TEXT_DRAW;
}
return 1;
}
// Start a task (timer)
task ColorTimer[1000]()
{
// Random colors
static color_rotation[] =
{
0xFF0000FF,
0x00FF00FF,
0x0000FFFF,
0x000000FF,
0xFFFFFFFF,
0xFF8000FF,
0xFF8080FF,
0x808080FF,
0x8080FFFF,
0x80FFFFFF
};
// Get style ID
new Style:styleid = TD_GetNamed("TEXT");
// Get style data
new td_data[E_TD_DATA];
TD_GetStyleData(styleid, td_data);
// Take a random color which isn't the previous color
new rand_color;
while(!rand_color || rand_color == td_data[E_TD_DATA_COLOUR])
{
rand_color = color_rotation[random(sizeof(color_rotation))];
}
// Set style color
TD_Colour(styleid, rand_color);
return 1;
}
Re: YSI: Examples for loading an XML file with y_td -
Scrillex - 11.03.2013
This looks good

But you need to more explain things but for your effort and something new... 6/10