SA-MP Forums Archive
sscanf2 issue - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: sscanf2 issue (/showthread.php?tid=188285)



sscanf2 issue - willsuckformoney - 07.11.2010

How to fix this? It only works for one person.

pawn Код:
dcmd_wank(playerid,params[])
{
    new string[128],ID,aName[MAX_PLAYER_NAME],Name[MAX_PLAYER_NAME],Float:x,Float:y,Float:z;
    GetPlayerName(playerid,Name,sizeof(Name)); GetPlayerName(ID,aName,sizeof(aName));
    GetPlayerPos(playerid,x,y,z);
    if(sscanf(params,"u",ID))
    {
        format(string,sizeof(string),"%s (%d) wanks on himself.",Name,playerid);
        SendClientMessageToAll(white,string);
        ApplyAnimation(playerid,"PAULNMAC","wank_out",4.1,1,1,1,1,1,1);
    }
    else if(IsPlayerInRangeOfPoint(ID,5,x,y,z))
    {
        format(string,sizeof(string),"%s (%d) wanks on %s (%d).",Name,playerid,aName,ID);
        SendClientMessageToAll(white,string);
        ApplyAnimation(playerid,"PAULNMAC","wank_out",4.1,1,1,1,1,1,1);
    } else return SendClientMessage(playerid,red,"Player is not close enough");
    return 1;
}
http://tinypic.com/r/2r2napy/7
http://tinypic.com/r/xpd5cz/7
http://tinypic.com/r/147ade/7
http://tinypic.com/r/34t1swn/7
http://tinypic.com/r/jsehkx/7

Look at the ids, the names and the lists, the one that has otto twice in it was supposed to be backfire.


Re: sscanf2 issue - GaGlets(R) - 07.11.2010

Let me guesss - only for you?

ApplyAnimation(playerid - cange that to "ID" in second part.


Re: sscanf2 issue - willsuckformoney - 07.11.2010

That's not it, one sec I take a screen and why would I wanna apply an animation to the person I am WANKING ON? The animation is like that because it applies for the player that types the command.


Re: sscanf2 issue - GaGlets(R) - 07.11.2010

better use zcmd...
pawn Код:
dcmd_wank(playerid,params[])
{
    if(!IsPlayerConnected(playerid)) return 1;
    new string[128],ID,aName[MAX_PLAYER_NAME],Name[MAX_PLAYER_NAME],Float:x,Float:y,Float:z;
    GetPlayerName(playerid,Name,sizeof(Name)); GetPlayerName(ID,aName,sizeof(aName));
    GetPlayerPos(playerid,x,y,z);
    if(sscanf(params,"u",ID))
    {
        format(string,sizeof(string),"%s (%d) wanks on himself.",Name,playerid);
        SendClientMessageToAll(white,string);
        ApplyAnimation(playerid,"PAULNMAC","wank_out",4.1,1,1,1,1,1,1);
    }
    if(!IsPlayerConnected(ID)) return SendClientMessage(playerid,red,"Invalid ID");
    if(IsPlayerInRangeOfPoint(ID,5,x,y,z))
    {
        format(string,sizeof(string),"%s (%d) wanks on %s (%d).",Name,playerid,aName,ID);
        SendClientMessageToAll(white,string);
        ApplyAnimation(playerid,"PAULNMAC","wank_out",4.1,1,1,1,1,1,1);
        // thoug there is needed animation for player `ID`
    } else return SendClientMessage(playerid,red,"Player is not close enough");
    return 1;
}
this should work.


Re: sscanf2 issue - willsuckformoney - 07.11.2010

pawn Код:
if(!IsPlayerConnected(playerid)) return 1;
That says if they are not connected, allow it.


Re: sscanf2 issue - GaGlets(R) - 07.11.2010

let me explane something

playerid = player who types the command
ID - its in your sscanf

So first of all

pawn Код:
if(!IsplayerConnected(playerid)) return 1;
// that would check if typer is connected or check if it is not a bot. or something like that.
! - means not. so if not connected.

you were making `elsle if` after sscanf and then `else` would never work.


Re: sscanf2 issue - Nomine - 08.11.2010

Your problem is that you use GetPlayerName on ID before you find out what ID is.
That means when you use "GetPlayerName(ID,aName,sizeof(aName));" ID is still new, uninitialised, aka 0.
So the name will always be the name of player 0.

pawn Код:
dcmd_wank(playerid,params[])
{
    new ID; <-- ID is empty which means 0
    ...
    GetPlayerName(ID,aName,sizeof(aName)); <-- ID is still 0
    ...
    if(sscanf(params,"u",ID)) <-- This is where you find out what ID is
    {
        ...
    }
    ...
    return 1;
}



Re: sscanf2 issue - GaGlets(R) - 08.11.2010

Quote:
Originally Posted by Nomine
Посмотреть сообщение
Your problem is that you use GetPlayerName on ID before you find out what ID is.
That means when you use "GetPlayerName(ID,aName,sizeof(aName));" ID is still new, uninitialised, aka 0.
So the name will always be the name of player 0.

pawn Код:
dcmd_wank(playerid,params[])
{
    new ID; <-- ID is empty which means 0
    ...
    GetPlayerName(ID,aName,sizeof(aName)); <-- ID is still 0
    ...
    if(sscanf(params,"u",ID)) <-- This is where you find out what ID is
    {
        ...
    }
    ...
    return 1;
}
Uhm.. Ahm.. ehm..
pawn Код:
dcmd_wank(playerid,params[])
{
    new string[128],ID,aName[MAX_PLAYER_NAME],Name[MAX_PLAYER_NAME],Float:x,Float:y,Float:z;
    GetPlayerName(playerid,Name,sizeof(Name));
    GetPlayerPos(playerid,x,y,z);
    if(sscanf(params,"u",ID))
    GetPlayerName(ID,aName,sizeof(aName));
I cant see there something about what you wrote.

FAIL?
HAHAHAHAHAAAaaaaaaaa oftopicer


Re: sscanf2 issue - willsuckformoney - 08.11.2010

ID is to take place for the player's ID....


Re: sscanf2 issue - GaGlets(R) - 08.11.2010

Fail to in fact he was right

willsuck - you need to be more careful.

like i sed `!` means `NOT`
`playerid` player who types
`IsPlayerConnected(playerid)` If typer is connected
`!IsPlayerConnected(playerid)` if typer is NOT connected

Just follow this and your command will work.
pawn Код:
dcmd_wank(playerid,params[])
{
    if(!IsPlayerConnected(playerid)) return 1;
    new string[90],ID,aName[MAX_PLAYER_NAME],Name[MAX_PLAYER_NAME],Float:x,Float:y,Float:z;
    GetPlayerName(playerid,Name,sizeof(Name));
    GetPlayerPos(playerid,x,y,z);
    if(sscanf(params,"u",ID))
    {
        format(string,sizeof(string),"%s (%d) wanks on himself.",Name,playerid);
        SendClientMessageToAll(white,string);
        ApplyAnimation(playerid,"PAULNMAC","wank_out",4.1,1,1,1,1,1,1);
    }
    if(!IsPlayerConnected(ID)) return SendClientMessage(playerid,red,"Invalid ID");
    if(IsPlayerInRangeOfPoint(ID,5,x,y,z))
    {
        GetPlayerName(ID,aName,sizeof(aName));
        format(string,sizeof(string),"%s (%d) wanks on %s (%d).",Name,playerid,aName,ID);
        SendClientMessageToAll(white,string);
        ApplyAnimation(playerid,"PAULNMAC","wank_out",4.1,1,1,1,1,1,1);
        // thoug there is needed animation for player `ID`
    } else return SendClientMessage(playerid,red,"Player is not close enough");
    return 1;
}