SA-MP Forums Archive
Which one is better ?? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Which one is better ?? (/showthread.php?tid=281002)



Which one is better ?? - Amel_PAtomAXx - 03.09.2011

Im Wondering , which way is better:

1.
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp(cmd,"/test",true)== 0)
    {
        SetTimer("test",1000,false);        
        return 1;
    }
    return 1;
}
forward test(playerid); // using playerid in forward
public test(playerid)
{
    SendClientMessage(playerid,0xFFFFFFFF," message :P ");
    return 1;
}
2.

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp(cmd,"/test",true)== 0)
    {
        SetTimerEx("test",1000,false,"i",playerid);    // or using SetTimerEx , getting playerid in " i "    
        return 1;
    }
    return 1;
}
forward test(i);
public test(i)
{
    SendClientMessage(i,0xFFFFFFFF," message :P ");
    return 1;
}
3.

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp(cmd,"/test",true)== 0)
    {
        SetPVarInt(playerid,"ID",playerid); // getting playerid in PVar
        SetTimer("test",1000,false);        
        return 1;
    }
    return 1;
}
forward test(playerid);
public test(playerid)
{
    new pID;
    pID = GetPVarInt(playerid,"ID");
    SendClientMessage(pID,0xFFFFFFFF," message :P ");
    return 1;
}



Re: Which one is better ?? - wouter0100 - 03.09.2011

1 Dont work, 2 works.


Re: Which one is better ?? - WoodPecker - 03.09.2011

I think the second one is more good.


Re: Which one is better ?? - Kieren - 03.09.2011

It's more on the lines of "Which one works?"; Go for the second method

Edit: You added the 3rd option - Isn't necessary and won't work.


Re: Which one is better ?? - wouter0100 - 03.09.2011

1, dont work.
2, This one you need to have.
3, dont work.


Re: Which one is better ?? - [L3th4l] - 03.09.2011

1. Even though you added "playerid" in the callback, it wouldn't send the msg to the player that used the cmd, it would send it to id 0

2. It will send the msg to the playerid that used the cmd.

3. Screw #3


Re: Which one is better ?? - Amel_PAtomAXx - 03.09.2011

Quote:
Originally Posted by [L3th4l]
View Post
3. Screw #3
what do you mean ?


Re: Which one is better ?? - =WoR=G4M3Ov3r - 03.09.2011

Obviously the second one.


Re: Which one is better ?? - Davz*|*Criss - 03.09.2011

1st and 3rd wont work, They said it above, try second one and it would work!

Thanks


Re: Which one is better ?? - dowster - 03.09.2011

Option 2 is the only option that would function correctly and here is why.
So you have this code and it all looks dandy
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp(cmd,"/test",true)== 0)
    {
        SetTimer("test",1000,false);        
        return 1;
    }
    return 1;
}
forward test(playerid); // using playerid in forward
public test(playerid)
{
    SendClientMessage(playerid,0xFFFFFFFF," message :P ");
    return 1;
}
You got your indenting, comments, etc. so you head in your localhost server to test it out and hooray! it works you got the message right? Well now lets try a different scenario, say you have a buddy who logs in and tries to test it but he complains that he didn't get the " message :P" but for some reason you got another " messsage :P". This is because since you didn't specify a variable to send to the function so playerid just became 0 which is the default for all new variables. This may be confusing because now you're thinking well how does OnPlayerUpdate, OnPlayerConnect, OnPlayerSpawn, etc. work. Doesn't putting playerid as a variable for the function automatically get the playerid? No, it does not. OnPlayerUpdate, OnPlayerConnect, and OnPlayerSpawn work because inside the samp-server.exe when it recieves the new data from the clients it will call the OnPlayerUpdate and send the id of the player that updated. "playerid" is really nothing special at all, if you wanted you could change your pawn natives very easily so you had
pawn Code:
public OnPlayerUpdate(hooplah)
as a function. Then everything you wanted to send to the player would look like this.
pawn Code:
public OnPlayerUpdate(hooplah)
{
    SendClientMessage(hooplah, 0x00FF00FF, "Update Received!"
    return 1;
}
and it would spam the client with "Update Received!" messages. Now that is why option 2 would be the [bold] only[/bold] way this would work. If I confused you in explaining this just say so and I will try to explain it differently.