Would these 3d text labels work in-game?
#1

Code:
pawn Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
#include <GetVehicleName>

new Text3D:PlayerInfo;
new Text3D:VehicleInfo1;
new Text3D:VehicleInfo2;

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

#endif

public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Blank Script");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    return 1;
}

public OnPlayerConnect(playerid)
{
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    return 1;
}

public OnPlayerSpawn(playerid)
{
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new string1[36];


    format(string1, sizeof(string1),"Vehicle Name: %s\nVehicle Health: %d",GetVehicleName(vehicleid), GetVehicleHealth(vehicleid));
    VehicleInfo1 = Create3DTextLabel(string1, 0x00FF00FF, 30.0, 40.0, 50.0, 40.0, 0);
    Attach3DTextLabelToPlayer(VehicleInfo1, playerid, 0.0, 0.0, 0.7);
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    new string1[79];
   
   
    format(string1, sizeof(string1),"Player Health: %d\nPlayer Armour: %d\nPlayer Weapon: %s\nPlayer Weapon Ammo: %d\nPlayer Money: $%d\nAdmin Level: %d",GetPlayerHealth(playerid), GetPlayerArmour(playerid), GetPlayerWeapon(playerid), GetPlayerAmmo(playerid), GetPlayerMoney(playerid));
    PlayerInfo = Create3DTextLabel(string1, 0x00FF00FF, 30.0, 40.0, 50.0, 40.0, 0);
    Attach3DTextLabelToPlayer(PlayerInfo, playerid, 0.0, 0.0, 0.7);
   
    new string2[36];
    new vehicleid = GetPlayerVehicleID(playerid);


    format(string2, sizeof(string2),"Vehicle Name: %s\nVehicle Health: %d",GetVehicleName(vehicleid), GetVehicleHealth(vehicleid));
    VehicleInfo2 = Create3DTextLabel(string2, 0x00FF00FF, 30.0, 40.0, 50.0, 40.0, 0);
    Attach3DTextLabelToPlayer(VehicleInfo2, playerid, 0.0, 0.0, 0.7);
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
Reply
#2

Why dont you try it?
Reply
#3

ill try, but ok, ill edit this if it works or not

EDIT: Its not working. Can somebody else test to confirm that it wont work?
Reply
#4

Small tip: Don't use OnPlayerUpdate,since it's called at every action the player does.(It will cause lag).Set up a custom public (remember to forward it) with a timer to update 3DTextLabels.
Reply
#5

Quote:
Originally Posted by Logitech90
Посмотреть сообщение
Small tip: Don't use OnPlayerUpdate,since it's called at every action the player does.(It will cause lag).Set up a custom public (remember to forward it) with a timer to update 3DTextLabels.
Can you show me a code? (I don't know how i would do that)
Reply
#6

You should read the SA-MP API documentation on these functions, as you're not using some of them correctly, for example GetPlayerHealth and GetPlayerArmour. They do not return the values, you need to pass a variable as the second argument to store the value in, for example:

pawn Код:
new Float: health; // Initialize a float to store the health

GetPlayerHealth(playerid, health); // Store the value in the float we initialized earlier
Also, as the above poster said, OnPlayerUpdate is a horrible choice to use for this snippet of code as it gets called every time a player sends a packet to the server, which can be many many times a second. Use a timer and a callback, for example:

pawn Код:
SetTimer("RefreshData", 1000, true); // Set a repeating timer every 1,000 miliseconds to call the RefreshData function

forward RefreshData();
public RefreshData()
{
    // Do what you need to do every second here.
    return 1;
}
Reply
#7

Would that make it so that whenever someone takes damage, it goes down right then?
Reply
#8

Quote:
Originally Posted by stormchaser206
Посмотреть сообщение
Would that make it so that whenever someone takes damage, it goes down right then?
There would be a 1 second delay, so it would be hardly noticeable.

If that's all you need it for, you could simply look at updating it using this callback:

https://sampwiki.blast.hk/wiki/OnPlayerTakeDamage

Which is called every time a player takes damage.

Also consider not creating the text-label constantly, create it once when the script starts or when the player joins the server and update it using this function:

https://sampwiki.blast.hk/wiki/Update3DTextLabelText

The key here is that you should be testing this yourself and reading the official PAWN documentation along with the SA-MP API documentation.
Reply
#9

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
You should read the SA-MP API documentation on these functions, as you're not using some of them correctly, for example GetPlayerHealth and GetPlayerArmour. They do not return the values, you need to pass a variable as the second argument to store the value in, for example:

pawn Код:
new Float: health; // Initialize a float to store the health

GetPlayerHealth(playerid, health); // Store the value in the float we initialized earlier
Also, as the above poster said, OnPlayerUpdate is a horrible choice to use for this snippet of code as it gets called every time a player sends a packet to the server, which can be many many times a second. Use a timer and a callback, for example:

pawn Код:
SetTimer("RefreshData", 1000, true); // Set a repeating timer every 1,000 miliseconds to call the RefreshData function

forward RefreshData();
public RefreshData()
{
    // Do what you need to do every second here.
    return 1;
}
Also, can you tell me where to put those?
And can you tell me what to put in the public?
Reply
#10

Quote:
Originally Posted by stormchaser206
Посмотреть сообщение
Also, can you tell me where to put those?
And can you tell me what to put in the public?
Put the code in there to update the Text3D instance with the new values like you were doing in OnPlayerUpdate.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)