sscanf2 issue
#1

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

Let me guesss - only for you?

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

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

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

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

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

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

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

ID is to take place for the player's ID....
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)