[Tutorial] RPC - Pawn.RakNet
#1

• Introduction
I'll be explaining what RPCs are and providing their parameters and IDs for use, including some example at the end of the topic.

Some RPCs have the same parameters as the function they are usually related to, while others don't, making their usage complicated.
• What RPC stands for?
RPC is an acronym for Remote Procedure Call, a protocol used to request a service from a client located on another computer on a network without having to understand the details of the network. As you already know, SA-MP uses RakNet network engine.

Say you exploded a player. The server will send an RPC (0x47 - RPC_CreateExplosion) to the client, requesting that explosion to be created.

The client also sends remote procedure calls back. Let's say you entered a vehicle, your client will send an incoming RPC to the server, informing that event (RPC_EnterVehicle).

RPC Types:
-Outcoming RPCs: RPCs sent by the server to the client.
-Incoming RPCs: RPCs sent by the client to the server.
Priorities:
-SYSTEM_PRIORITY: Internal Used by RakNet to send above-high priority messages.

-HIGH_PRIORITY: High priority messages are sent before medium priority messages.

-MEDIUM_PRIORITY: Medium priority messages are sent before low priority messages.

-LOW_PRIORITY: Low priority messages are only sent when no other messages are waiting.
Reliabilities:
-RELIABLE_SEQUENCED: Reliable sequenced packets are UDP packets monitored by a reliability layer to ensure they arrive at the destination and are sequenced at the destination.
Advantages - You get the reliability of UDP packets, the ordering of ordered packets, yet don't have to wait for old packets. More packets will arrive with this method than with the unreliable sequenced method, and they will be distributed more evenly. The most important advantage however is that the latest packet sent will arrive, where with unreliable sequenced the latest packet sent may not arrive.
Disadvantages - Wasteful of bandwidth because it uses the overhead of reliable UDP packets to ensure late packets arrive that just get ignored anyway.

-RELIABLE_ORDERED: Reliable ordered packets are UDP packets monitored by a reliability layer to ensure they arrive at the destination and are ordered at the destination. Advantages - The packet will get there and in the order it was sent. These are by far the easiest to program for because you don't have to worry about strange behavior due to out of order or lost packets.
Disadvantages - Retransmissions and acknowledgments can add significant bandwidth requirements. Packets may arrive very late if the network is busy. One late packet can delay many packets that arrived sooner, resulting in significant lag spikes. However, this disadvantage can be mitigated by the clever use of ordering streams.

-RELIABLE: Reliable packets are UDP packets monitored by a reliablilty layer to ensure they arrive at the destination.
Advantages - You know the packet will get there. Eventually...
Disadvantages - Retransmissions and acknowledgments can add significant bandwidth requirements. Packets may arrive very late if the network is busy. No packet ordering.

-UNRELIABLE_SEQUENCED: Unreliable sequenced packets are the same as unreliable packets, except that only the newest packet is ever accepted. Older packets are ignored. Advantages - Same low overhead as unreliable packets, and you don't have to worry about older packets changing your data to old values.
Disadvantages - A LOT of packets will be dropped since they may never arrive because of UDP and may be dropped even when they do arrive. These packets are the first to get dropped if the send buffer is full. The last packet sent may never arrive, which can be a problem if you stop sending packets at some particular point.

-UNRELIABLE: Unreliable packets are sent by straight UDP. They may arrive out of order, or not at all. This is best for data that is unimportant, or data that you send very frequently so even if some packets are missed newer packets will compensate.
Advantages - These packets don't need to be acknowledged by the network, saving the size of a UDP header in acknowledgment (about 50 bytes or so). The savings can really add up.
Disadvantages - No packet ordering, packets may never arrive, these packets are the first to get dropped if the send buffer is full.
• Examples
RPC_ShowActor
ID: 171
Parameters: WORD wActorID, DWORD dSkinID, float x, float y, float z, float angle, float health

Plugin (Example taken from my YSF fork)
PHP Code:
RakNet::BitStream bs;
bs.Write((WORD)5); //Actor ID.
bs.Write((DWORD)287); //The actor's skin ID.
bs.Write((float)0.0); //X.
bs.Write((float)0.0); //Y.
bs.Write((float)0.0); //Z.
bs.Write((float)50.0); //Angle.
bs.Write((float)100.0); //Actor's Health.
pRakServer->RPC(&RPC_ShowActor, &bsLOW_PRIORITYRELIABLE_ORDERED0pRakServer->GetPlayerIDFromIndex(23), 00); 
&RPC_ShowActor: Integer with the RPC id.
&bs: Contains the data written above (packed bits).
LOW_PRIORITY: RPC's priority.
RELIABLE_ORDERED: RPC's reliablity.
pRakServer->GetPlayerIDFromIndex(23): The player about to receive the RPC.
Pawn.RakNet
PHP Code:
new BitStream:bs BS_New();
BS_WriteValue(
    
bs,
    
PR_UINT165//Actor ID.
    
PR_UINT32287//The actor's skin ID.
    
PR_FLOAT0.0//X.
    
PR_FLOAT0.0//Y.
    
PR_FLOAT0.0//Z.
    
PR_FLOAT50.0//Angle.
    
PR_FLOAT100.0 //Actor's Health.
);
BS_RPC(bs23171PR_LOW_PRIORITYPR_RELIABLE_ORDERED);
BS_Delete(bs); 
bs: BitStream with the data above (packed bits).
23: The player about to receive the RPC.
171: RPC_ShowActor's ID.
PR_LOW_PRIORITY: RPC's priority.
PR_RELIABLE_ORDERED: RPC's reliability
• RPC List with parameters
Github

The list isn't entirely done, but has a considerable amount of RPCs with proper information.
Reply
#2

Finally People out there gonna understand the usage of Pawn.Raknet!
Reply
#3

Didn't knew about that, thanks for the kind info Jelly.
Reply
#4

Quote:
Originally Posted by Sunehildeep
View Post
Didn't knew about that, thanks for the kind info Jelly.
know*

O.T Great tutorial very useful information.
Reply
#5

GOD OF PAWNO
Reply
#6

My man back on the game! Welcome back Jelly.
Reply
#7

Yes, I was waiting for a tutorial like this, thanks a lot!
+REP.
Reply
#8

You wrote some nice stuff there, I hope you'll translate the second part also. These guides are very useful.
Reply
#9

Will be updating the RPC list soon.
Reply
#10

Very nice.
Can you provide more details when we should do that or that in which circunstances. I mean, let's take messages priorities. In your example, why do you set to PR_LOW_PRIORITY? Isn't important to renew the actor when a player see it? Or I missunderstood something? :x
Reply
#11

Quote:
Originally Posted by Dayrion
View Post
Very nice.
Can you provide more details when we should do that or that in which circunstances. I mean, let's take messages priorities. In your example, why do you set to PR_LOW_PRIORITY? Isn't important to renew the actor when a player see it? Or I missunderstood something?
LOW_PRIORITY means the message (RPC) will only be sent when there is no other message waiting. As for "renew the actor", you probably mean re-stream. Yes, you would have to re-show the actor in-case you plan on showing out of the original position and somebody gets in a certain range of it.
Reply
#12

Excellent i will try to make an admin and anti cheat system!
Reply
#13

Quote:
Originally Posted by Jelly23
View Post
LOW_PRIORITY means the message (RPC) will only be sent when there is no other message waiting. As for "renew the actor", you probably mean re-stream. Yes, you would have to re-show the actor in-case you plan on showing out of the original position and somebody gets in a certain range of it.
That didn't answer to my question /:
I know why you have to re-show actor. My question was about priority you set to re-show the actor. Why especiaLly this one?
Reply
#14

Quote:
Originally Posted by Dayrion
View Post
That didn't answer to my question /:
I know why you have to re-show actor. My question was about priority you set to re-show the actor. Why especiaLly this one?
The priority you want your message to be sent is up to you. In that case, I want my message to be sent after there is no other waiting.
Reply
#15

What is ID the MoveObject and SetObjectMaterial / Text ?
Reply
#16

Quote:
Originally Posted by TiW
View Post
What is ID the MoveObject and SetObjectMaterial / Text ?
I will be updating the list when I can, I know some RPCs are missing, but won't be for long.

Information about reliability updated.
Reply
#17

Quote:
Originally Posted by Jelly23
View Post
The priority you want your message to be sent is up to you. In that case, I want my message to be sent after there is no other waiting.
Alright, this sound weird. Thanks for the precision.
Reply
#18

Pretty useful, thank you for your effort. Seems like you can do stuff with RPCs you could also already do with existing PAWN functions, the difference being that you can control stuff on a more fine-grained level with RPCs. Essentially there is no benefit to using RPCs that are already accessible via PAWN. So, where exactly do you get the names of the RPCs from?
Reply
#19

Quote:
Originally Posted by Manyula
View Post
Pretty useful, thank you for your effort. Seems like you can do stuff with RPCs you could also already do with existing PAWN functions, the difference being that you can control stuff on a more fine-grained level with RPCs. Essentially there is no benefit to using RPCs that are already accessible via PAWN. So, where exactly do you get the names of the RPCs from?
You probably mean the IDs. there is a topic made by kurta999 which explains how to get them.

RPC List updated (Incoming RPCs).
Reply
#20

Where is the RPC list?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)