SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 15/11/2017, 02:26 PM   #1
Jelly23
Guest
 
Posts: n/a
Default RPC - Pawn.RakNet

• 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.

Last edited by Jelly23; 24/01/2018 at 04:06 PM.
  Reply With Quote
Old 15/11/2017, 02:34 PM   #2
Zeth
Huge Clucker
 
Zeth's Avatar
 
Join Date: Feb 2017
Location: Debjit's Place | India
Posts: 463
Reputation: 77
Default Re: RPC - Pawn.RakNet

Finally People out there gonna understand the usage of Pawn.Raknet!
__________________


Zeth is offline   Reply With Quote
Old 15/11/2017, 02:35 PM   #3
StrikerZ
High-roller
 
StrikerZ's Avatar
 
Join Date: Mar 2016
Location: India
Posts: 1,123
Reputation: 154
Default Re: RPC - Pawn.RakNet

Didn't knew about that, thanks for the kind info Jelly.
__________________
StrikerZ is offline   Reply With Quote
Old 15/11/2017, 02:45 PM   #4
HydraHumza
Gangsta
 
HydraHumza's Avatar
 
Join Date: Oct 2014
Posts: 652
Reputation: 130
Default Re: RPC - Pawn.RakNet

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.
__________________
Quote:
Originally Posted by Kalcor View Post
The fact is, I am right. And if you think I'm wrong, you are wrong.
HydraHumza is offline   Reply With Quote
Old 15/11/2017, 04:47 PM   #5
DeitY
Huge Clucker
 
DeitY's Avatar
 
Join Date: Aug 2012
Location: Serbia
Posts: 319
Reputation: 14
Default Re: RPC - Pawn.RakNet

GOD OF PAWNO
__________________
Serbian RolePlay Server! 7 Years Community so far and going~

DeitY is online now   Reply With Quote
Old 15/11/2017, 05:15 PM   #6
Logic_
High-roller
 
Logic_'s Avatar
 
Join Date: Jun 2015
Location: Oblivion (#RIPX)
Posts: 1,461
Reputation: 263
Default Re: RPC - Pawn.RakNet

My man back on the game! Welcome back Jelly.
__________________
RIP XXXTentacion [1998-2018]

My Releases: Click me!

Past experiences:
Ex- Developer of COD: Black Ops 3 [2017 - 2018], Palomino Creek RP [2018], NEG [2017], Zombieland [2015]
Logic_ is offline   Reply With Quote
Old 15/11/2017, 06:42 PM   #7
Eoussama
High-roller
 
Eoussama's Avatar
 
Join Date: Jul 2016
Location: Kingdom of Morocco // Tangier
Posts: 1,265
Reputation: 227
Default Re: RPC - Pawn.RakNet

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

|===[Web taxi]===|
List of my work
Github
Pastebin

|===[Interesting topics]===|
Semantic Versioning


Eoussama is online now   Reply With Quote
Old 15/11/2017, 07:52 PM   #8
RIDE2DAY
Huge Clucker
 
RIDE2DAY's Avatar
 
Join Date: Jul 2015
Location: Modena, Italy
Posts: 221
Reputation: 367
Default Re: RPC - Pawn.RakNet

You wrote some nice stuff there, I hope you'll translate the second part also. These guides are very useful.
RIDE2DAY is offline   Reply With Quote
Old 18/11/2017, 05:04 PM   #9
Jelly23
Guest
 
Posts: n/a
Default Re: RPC - Pawn.RakNet

Will be updating the RPC list soon.
  Reply With Quote
Old 18/11/2017, 08:10 PM   #10
Dayrion
High-roller
 
Dayrion's Avatar
 
Join Date: Jan 2016
Location: France
Posts: 1,781
Reputation: 230
Default Re: RPC - Pawn.RakNet

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
__________________
actor_plus - v4.1.2
« I'm a goner, somebody catch my breath,
I'm a goner, somebody catch my breath »
Dayrion is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Plugin] Pawn.RakNet YourShadow Plugin Development 201 31/05/2018 04:21 PM
[Tutorial] Pacotes - Pawn.RakNet Jelly23 Lançamentos/Releases 32 10/02/2018 07:03 PM
VC:MP RakNet Version? Christopher. Everything and Nothing 1 27/01/2010 09:17 PM


All times are GMT. The time now is 02:33 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.