[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


Messages In This Thread
Introduction to some awesome-yet-unknown-to-many functions/callbacks - by CreativityLacker - 24.02.2013, 13:47
AW: Introduction to some awesome-yet-unknown-to-many functions/callbacks - by NaS - 24.02.2013, 20:36
Re: AW: Introduction to some awesome-yet-unknown-to-many functions/callbacks - by CreativityLacker - 25.02.2013, 07:48

Forum Jump:


Users browsing this thread: 2 Guest(s)