Callback
#1

How do you make something like

PHP код:
public OnPlayerGameTime(playeridhourminutesecond)
{
if(
hour >= && !minute && !second)
{
// You have played for X hour:00:00
}

I am trying to implement it on jadmin3's include but I have no idea on how I can hook it up on a function in the script then remotely call it on the include.

Structure in the script
PHP код:
JakAdmin3_OnPlayerGameTime(playeridhourminutesecond)
{

jadmin3
PHP код:
public OnPlayerGameTime(playeridhourminutesecond); 
Reply
#2

Quote:
Originally Posted by JaKe Elite
Посмотреть сообщение
How do you make something like

PHP код:
public OnPlayerGameTime(playeridhourminutesecond)
{
if(
hour >= && !minute && !second)
{
// You have played for X hour:00:00
}

I am trying to implement it on jadmin3's include but I have no idea on how I can hook it up on a function in the script then remotely call it on the include.

Structure in the script
PHP код:
JakAdmin3_OnPlayerGameTime(playeridhourminutesecond)
{

jadmin3
PHP код:
public OnPlayerGameTime(playeridhourminutesecond); 
Код:
stock GetPlayerOnLine(playerid){
	new sec,mins,hours,string[40];
	sec = (NetStats_GetConnectedTime(playerid)/1000)%60;
	mins = (NetStats_GetConnectedTime(playerid)/60000)%60;
	hours = (NetStats_GetConnectedTime(playerid)/3600000);
	format(string,sizeof(string),"Time: %02d:%02d:%02d",hours,mins,sec);
	SendClientMessage(playerid, -1,string);
	return true;
}
Reply
#3

I know how to hook them up and all that, What i am saying is how can you make a check and hookup the User[playerid][accountGame] over the JakAdmin3_OnPlayerGameTime callback parameters like

hour = User[playerid][accountGame][2]
minute = User[playerid][accountGame][1]
second = User[playerid][accountGame][0]

then jadmin3 will remotely call this callback making it able to be used on the other script

PHP код:
public OnPlayerGameTime(playeridhourminutesecond

if(
hour >= && !minute && !second

// You have played for X hour:00:00 


I am not in the best shape right now to explain it properly but HEY i am trying my best
Reply
#4

bump
4char
Reply
#5

If it's FS, then CallRemoteFunction, if include, CallLocalFunction.
Reply
#6

Alright I have just woken up, hoping that I could explain it more clearer than I did yesterday.

What I am trying to do is to create an OnPlayerGameTime function for other players to use, they can do and check if the player reached a specific hour, minutes or seconds of their online time.

The problem is....
I have no idea on how am I gonna do the parameters of OnPlayerGameTime hooking it's hour parameter to my User[playerid][accountGame][2], minute to User[playerid][accountGame][1] and second to User[playerid][accountGame][0]
Reply
#7

Make a function in the FS that returns the value of these variables. And call that function through the include.
Reply
#8

I really have no clue but this is what I have in my mind xD

PHP код:
JakAdmin3_OnPlayerGameTime(playeridUser[playerid][accountGame][2], User[playerid][accountGame][1], User[playerid][accountGame][0])
{
    return 
1;

at least I am trying lol
Reply
#9

Alright I have tried doing this

PHP код:
function:check_playingtime(playerid, &hour, &minute, &second)
{
    
hour User[playerid][accountGame][2];
    
minute User[playerid][accountGame][1];
    
second User[playerid][accountGame][0];
    return 
1;
}

stock GetPlayerGameTime(playerid, &hour, &minute, &second)
{
    return 
CallRemoteFunction("check_playingtime""dddd"playeridhourminutesecond);
}

CMD:checktime(playeridparams[])
{
    new 
string[92], x[3];
    
GetPlayerGameTime(playeridx[0], x[1], x[2]);
    
format(stringsizeof(string), "Total Playing Time: %02d:%02d:%02d"x[0], x[1], x[2]);
    
SendClientMessage(playerid, -1string);
    return 
1;

but no luck, the value returned by GetPlayerGameTime is NULL.
Reply
#10

up
4char
Reply
#11

No idea what you're trying to do here. Why doesn't your checktime command just use the User[playerid][accountGame] enum directly?
Reply
#12

I am trying to create an include that returns the script's AccountGame by linking them using CallRemoteFunction, /checktime is from another script.
Reply
#13

Oh, I see. That's not going to work IMHO, I don't see how you could pass arguments by reference through CallRemoteFunction.

What you need to use here is PVars: do a SetPVarInt on "playertime_hours", "playertime_minutes" and "playertime_seconds", this way you can access these variables from any filterscript.
Reply
#14

Isn't there any other way to do it?

PVars are slow.
Reply
#15

I have tried PVar and it works though.
Reply
#16

The whole code is an example. (This include is about detect when a player use Pay'n'Spray to repair vehicle):
PHP код:
hook OnPlayerUpdate(playerid)
{
    if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER
    {
        for(new 
sizeof(PayNSprayPos) - 1>= 0i--)
        {
            if(
IsPlayerInRangeOfPoint(playerid3.3PayNSprayPos[i][0], PayNSprayPos[i][1], PayNSprayPos[i][2]) && GetPlayerMoney(playerid) >= 100)
            {
                static
                    
Float:x,
                    
Float:y,
                    
Float:z;
                
GetPlayerPos(playeridxyz);
                if(
p_A_Flood[playerid] < gettime())
                    
p_Timer[playerid] = SetTimerEx("Ji_Timer_PNS"100true"iifff"playeridGetPlayerVehicleID(playerid), xyz);
            }
        }
    }
}
forward Ji_Timer_PNS(playeridvehicleidFloat:xFloat:yFloat:z);
public 
Ji_Timer_PNS(playeridvehicleidFloat:xFloat:yFloat:z)
{
    static 
        
Float:Pos[3],
        
Float:vHP;
    
GetVehicleHealth(vehicleidvHP);
    
GetPlayerPos(playeridPos[0], Pos[1], Pos[2]);
    if(
== Pos[0] && == Pos[1] && == Pos[2])
    {
        if(
p_A_Flood[playerid] > gettime())
            return 
1;
        
        new 
v_Color1[vehicleid] ? -random(255),
            
v_Color2[vehicleid] ? -random(255);
        
p_A_Flood[playerid] = gettime() + TEMPS_MOYEN;
        
p_Timer[playerid] = 0;
        
KillTimer(p_Timer[playerid]);
        if(!
v_Color1[vehicleid] && !v_Color2[vehicleid])
        {
            
ChangeVehicleColor(vehicleidab);
        }
        
vHP 1000.0 vHP;
        
CallLocalFunction("Ji_OnCarResprayAtPNS""iiiif"playeridGetPlayerVehicleID(playerid), abvHP <= 0.00 0.00 vHP);
    }
    return 
1;
}
forward Ji_OnCarResprayAtPNS(playeridvehicleidcolor1color2Float:hp_recovered); 
In your gamemode where there is your include:

PHP код:
public Ji_OnCarResprayAtPNS(playeridvehicleidcolor1color2Float:hp_recovered)
{
    
AdminWarn("[DEBUG] playerid: %i, vehicleid: %i, color1: %i, color2: %i, hp_recovered: %0.3f"playeridvehicleidcolor1color2hp_recovered);
    if(
hp_recovered 280.0)
    {
        foreach(new 
Player)
        {
            if(
== playerid || !IsPlayerInAnyVehicle(i))
                continue;
            if(
GetPlayerVehicleID(i) == vehicleid)
            {
                
SCM(i0xff00ffff"[REPARATION] {e699ff}Your have to pay 100$ too.");
                
GivePlayerMoney(i, -100);
            }
        }
    }
    return 
1;

Reply
#17

Dayrion, wrong thread?

JaKe, PVars are slow? Can you support this claim with relevant benchmarks pertaining to your situation?
Reply
#18

Quote:
Originally Posted by TheCman
Посмотреть сообщение
Dayrion, wrong thread?

JaKe, PVars are slow? Can you support this claim with relevant benchmarks pertaining to your situation?
I don't know to be honest, I used this function once in my early version of JakAdmin but I was told that PVars is slow so I had to remove the jadmin3 include temporarily until I have found about the CallRemoteFunction technique.
Reply
#19

Quote:
Originally Posted by TheCman
Посмотреть сообщение
Dayrion, wrong thread?

JaKe, PVars are slow? Can you support this claim with relevant benchmarks pertaining to your situation?
No, I guess.
Jake is talking about making his own callback. I showed him an example how to make a callback.
As Misiur said previously :
Quote:
Originally Posted by Misiur
Посмотреть сообщение
If it's FS, then CallRemoteFunction, if include, CallLocalFunction.
Код HTML:
CallRemoteFunction(const function[], const format[], {Float,_}:...)
CallLocalFunction(const function[], const format[], {Float,_}:...)
When you want your callback be called, your need to use CallRemoteFunction/CallLocalFunction like I did in my example.

PHP код:
 CallLocalFunction("Ji_OnCarResprayAtPNS""iiiif"playeridGetPlayerVehicleID(playerid), abvHP <= 0.00 0.00 vHP); 
Ji_OnCarResprayAtPNS is the name of my callback
"iiiif" are the parameters
Arguments are what parameters take when the function is called.
Reply
#20

Daryion, no, he's not trying to make a callback. He's trying to make a remote function that returns 3 values at once. Since passing arguments by reference using CallRemoteFunction will not work, both of your posts are irrelevant.

What he actually needs to do is save the time in a PVar. The whole concept of PVars is that they are meant to be accessed remotely.

Also Jake, you mentioned that PVars work, so can you +rep me since this is the solution? Thanks in advance.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)