Quantcast
Channel: SA-MP Forums
Viewing all articles
Browse latest Browse all 18226

[Tutorial] OnPlayerLoginAsRcon Callback

$
0
0
Today gonna learn ya how to make OnPlayerLoginAsRcon(playerid) callback ;_; so let's begin,

how will we do it? Well, we gonna make a simple var and reset it / make the value of it 0 on player connect, then on his login as rcon we will search for player that is rcon and his value is 0 we will make it 1 and get his id.

Words easer than scripts ;_;.

first we will add samp team and foreach loops includes,

Foreach download link:
http://forum.sa-mp.com/showthread.php?t=570868

PHP Code:

#include a_samp
#include foreach 

second we will make / add our var

PHP Code:

new P_Rconz[MAX_PLAYERS]; // we add [MAX_PLAYERS] to make it var per player... 

now we will reset our var on player connect [ if he is rcon we won't touch it cause players keep rcon, if /gmx used c: ]

PHP Code:

public OnPlayerConnect(playerid) { // on player connect callback
   
if(!IsPlayerAdmin(playerid)) P_Rconz[playerid] = 0// var reset with if player not rcon check to avoid bugs when /rcon gmx used...
   
return 1;


now we will do some job onrconloginattempt to check if new player loggedin as rcon

PHP Code:

public OnRconLoginAttempt(ip[], password[], success// on rconloginattempt
{
   if(
successSetTimer("FollowDaRconz"2500);// check if successed to login in and make a timer to search for the player : NOTE I used timer cause it not make player rcon directly after he login on this callback...


now we will make our timer codes

PHP Code:

forward public FollowDaRconz(); // forwarding our timer
public FollowDaRconz() { // when our timer being called
   
foreach(new Player) { // loob between available players ids
      
if(IsPlayerAdmin(i) && !P_Rconz[i]) { // if player is rcon and his rcon var is 0
         
CallRemoteFunction("OnPlayerLoginAsRcon""i"i); // call our remote functions of OnPlayerLoginAsRcon
         
P_Rconz[i] = 1// increase Rcon var of the player
      
}
   }


now we can do multi things with our OnPlayerRconLogin callback,
example here I got player name and shared it for players...

PHP Code:

forward public OnPlayerLoginAsRcon(rconid); // forwarding our OnPlayerRconLogin callback
public OnPlayerLoginAsRcon(rconid) {// when it got called
   
new name[MAX_PLAYERS],str[80]; // add new vars to save player name and put it on a message
   
GetPlayerName(rconidnamesizeof name); // get player name on our var
   
format(strsizeof str,"%s Logged In As Rcon",name); // format our message to put player name and some texts in it
   
SendClientMessageToAll(-1str); // send the message to all players


I hope it will be useful for ya ;_;
Here's CallRemoteFunctions wiki page...
https://wiki.sa-mp.com/wiki/CallRemoteFunction

Full code:
PHP Code:

#include a_samp
#include foreach
new P_Rconz[MAX_PLAYERS];
public 
OnPlayerConnect(playerid) { 
   if(!
IsPlayerAdmin(playerid)) P_Rconz[playerid] = 0
   return 
1;
}
public 
OnRconLoginAttempt(ip[], password[], success// on rconloginattempt
{
   if(
successSetTimer("FollowDaRconz"2500);// check if successed to login in and make a timer to search for the player : NOTE I used timer cause it not make player rcon directly after he login on this callback...
}
forward public FollowDaRconz(); // forwarding our timer
public FollowDaRconz() { // when our timer being called
   
foreach(new Player) { // loob between available players ids
      
if(IsPlayerAdmin(i) && !P_Rconz[i]) { // if player is rcon and his rcon var is 0
         
CallRemoteFunction("OnPlayerLoginAsRcon""i"i); // call our remote functions of OnPlayerLoginAsRcon
         
P_Rconz[i] = 1// increase Rcon var of the player
      
}
   }
}
forward public OnPlayerLoginAsRcon(rconid); // forwarding our OnPlayerRconLogin callback
public OnPlayerLoginAsRcon(rconid) {// when it got called
   
new name[MAX_PLAYERS],str[80]; // add new vars to save player name and put it on a message
   
GetPlayerName(rconidnamesizeof name); // get player name on our var
   
format(strsizeof str,"%s Logged In As Rcon",name); // format our message to put player name and some texts in it
   
SendClientMessageToAll(-1str); // send the message to all players



Viewing all articles
Browse latest Browse all 18226

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>