Which one is better ??
#1

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;
}
Reply
#2

1 Dont work, 2 works.
Reply
#3

I think the second one is more good.
Reply
#4

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.
Reply
#5

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

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
Reply
#7

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

Obviously the second one.
Reply
#9

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

Thanks
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)