onplayerconnect help
#1

Ok im making a happy hour system, this is how it works, if an admin type the command /happyhour it will only give the happy hour rewards to those who were online when the admin type /happy hour. This is how i want it to work, when a admin type /happy hour it will give rewards to those who are online at the time and to those who came after the admin has executed the command. Can someone tell me what to do or leave a example code below.
Reply
#2

You can use a state system:

PHP код:
//Global var:
new bool:happy_hour;
//If the admin types the happy hour cmd:
happy_hour true//started
for(new i=GetPlayerPoolSize(); != -1i--)
{
    if(
IsPlayerConnected(i) && !IsPlayerNPC(i)) SetPVarInt(i, !"Happy_Hour"1);
}
//OnPlayerConnect
if(happy_hourSetPVarInt(playerid, !"Happy_Hour"2);
//So and now you can check the values:
switch(GetPVarInt(playerid, !"Happy_Hour"))
{
    case 
0:
    {
        
//actually impossible to have...except you set happy_hour somewhere to false :) and a player reconnects
        //or you check this value..before it was ever set :)
    

    case 
1:
    {
        
//Here the player was online, while the command was executed
    
}
    case 
2:
    {
        
//Here the player connected after the command was executed :)
    
}

Remeber, PVars get deleted if the player disconnects.
So when he was online...disconnects, and connect, he get state 2

If you wanna work around that, you have to save the values

Hope..i could help you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)