[Tutorial] Introduction to some awesome-yet-unknown-to-many functions/callbacks
#1

Introduction
to many awesome functions


Functions/callbacks -


pawn Код:
AddPlayerClassEx(teamid, skin, Float:x, Float:y, Float:z, Float:Angle, weapon1, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo)
https://sampwiki.blast.hk/wiki/AddPlayerClassEx

pawn Код:
public OnPlayerClickMap(playerid, Float:fX, Float:fY, Float:fZ)
https://sampwiki.blast.hk/wiki/OnPlayerClickMap

pawn Код:
SetPlayerPosFindZ(playerid, Float:x, Float:y, Float:z)
https://sampwiki.blast.hk/wiki/SetPlayerPosFindZ

pawn Код:
Valstr(dest[], value, bool:pack=false)
https://sampwiki.blast.hk/wiki/Valstr






1. AddPlayerClassEx
Syntax -
pawn Код:
(teamid, skin, Float:x, Float:y, Float:z, Float:Angle, weapon1, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo)


This function works the SAME way as AddPlayerClass, except with an additional 'team_id' parameter.

Usually, what I see is people adding classes OnGameModeInIt and setting team's under OnPlayerRequestClass

Using this function, this -

pawn Код:
public OnGameModeInIt()
{
    AddPlayerClass(...);
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    if(classid == 0) return SetPlayerTeam(playerid, 1);
    return 1;
}
becomes
pawn Код:
public OnGameModeInIt()
{
    AddPlayerClassEx(teamid, ...);
    return 1;
}
It will automatically set the player's team AFTER the player chooses the class.
I'd ALSO like to point out, OnPlayerRequestClass is called when player switches class, NOT when he clicks on 'Spawn'.







2. OnPlayerClickMap
Syntax -
pawn Код:
(playerid, Float:fX, Float:fY, Float:fZ)
This callback is called everytime a player opens the PAUSE >> MAP menu and clicks on a position.
This callback can be very useful to create innovative features like a GPS or somethin'


pawn Код:
public OnPlayerClickMap(playerid, Float:fX, Float:fY, Float:fZ)
{
    for(new x=0;x < MAX_PLAYERS; x++)
    {
         new Float:Pos[3];
         GetPlayerPos(x, Pos[0], Pos[1], Pos[2]);
         if(Pos[0] == fX && Pos[1] == fY)
         {
              SendClientMessage(playerid, -1, "[SERVER] You clicked on a player!!!! :D ");
         }
         break;
    }
    return 1;
}
This can be MUCH further enhanced, though I do not know how efficient it is.






3. SetPlayerPosFindZ
Syntax -
pawn Код:
(playerid, Float:x, Float:y, Float:z)
This function does EXACTLY what SetPlayerPos does, except -
Player's pos is set to the inserted X
Player's pos is set to the inserted Y
Player's pos IS NOT SET to the inserted Z. Instead, it's set the level wherever ground is available.

In other words, You put in the X and Y, and the server finds the Z. This works a lot like MapAndreas's 2D-Z function, except that nobody has managed to manipulate it to use it to get Z coords without players.
You can use an NPC, set his position to X and Y, and send this data to the server <= Slow but just an idea






4. Valstr
Syntax
-
pawn Код:
(dest[], value, bool:pack=false)
This function does exactly OPPOSITE of strval

Strval => Returns the value of a STRING into an integer.
Valstr => Stores an INTEGER into a STRING (Optionally, you can pack it [I'm not here to explain packed and unpacked strings])

Basically, if you have a variable with value 5, you can make this into a STRING without using format



Quote:
Originally Posted by NaS
Посмотреть сообщение
SetPlayerPosFindZ is not working serverwise, it is working clientside, thats why it is not possible to get any information out of it.

It is not working with NPCs, because NPCs are no real clients.

Furthermore, it is not working very accurate. If the position you are setting a player to is NOT rendered by the client, the player will not get set exactly on the ground (he will spawn too high or underneath the map).

You should use the function like this to make it work correctly in every area:

Код:
SetPlayerPos(playerid, x, y, z);

Set a timer about 100-200ms (or even shorter) to let the client render the zone and THEN use FindZ afterwards:

SetPlayerPosFindZ(playerid, x, y, z);
Same for OnPlayerClickMap, the Z coordinate is only accurate, if the X/Y coordinates are in a specific range of the player.
You could use the above "script" to make an easy (admin) teleporter for a debug script.

Greets
NOTE - I know this is a very BRIEF explanation. The main aim of this topic was to make people aware of functions which make our life much easier. I hope I've helped you and if you want to, feel free to suggest any additions/subtractions to/from this topic, it's just a quicky.
Reply
#2

SetPlayerPosFindZ is not working serverwise, it is working clientside, thats why it is not possible to get any information out of it.

It is not working with NPCs, because NPCs are no real clients.

Furthermore, it is not working very accurate. If the position you are setting a player to is NOT rendered by the client, the player will not get set exactly on the ground (he will spawn too high or underneath the map).

You should use the function like this to make it work correctly in every area:

Код:
SetPlayerPos(playerid, x, y, z);

Set a timer about 100-200ms (or even shorter) to let the client render the zone and THEN use FindZ afterwards:

SetPlayerPosFindZ(playerid, x, y, z);
Same for OnPlayerClickMap, the Z coordinate is only accurate, if the X/Y coordinates are in a specific range of the player.
You could use the above "script" to make an easy (admin) teleporter for a debug script.


Btw, nice tutorial, I think it will remember some people of these functions and callbacks and other players will get to know them.
I wrote this so you could maybe write the above things into your post, otherwise some players may think the function may be not working like it should, although it is a VERY useful thing as you said.

Greets
Reply
#3

Quote:
Originally Posted by NaS
Посмотреть сообщение
SetPlayerPosFindZ is not working serverwise, it is working clientside, thats why it is not possible to get any information out of it.

It is not working with NPCs, because NPCs are no real clients.

Furthermore, it is not working very accurate. If the position you are setting a player to is NOT rendered by the client, the player will not get set exactly on the ground (he will spawn too high or underneath the map).

You should use the function like this to make it work correctly in every area:

Код:
SetPlayerPos(playerid, x, y, z);

Set a timer about 100-200ms (or even shorter) to let the client render the zone and THEN use FindZ afterwards:

SetPlayerPosFindZ(playerid, x, y, z);
Same for OnPlayerClickMap, the Z coordinate is only accurate, if the X/Y coordinates are in a specific range of the player.
You could use the above "script" to make an easy (admin) teleporter for a debug script.


Btw, nice tutorial, I think it will remember some people of these functions and callbacks and other players will get to know them.
I wrote this so you could maybe write the above things into your post, otherwise some players may think the function may be not working like it should, although it is a VERY useful thing as you said.

Greets
Thanks for telling me about this, I just saw them on the wiki and tried them and thought about sharing them.
Added your reply to the main post
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)