SA-MP Forums Archive
Bad code, help me - 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: Bad code, help me (/showthread.php?tid=598866)



Bad code, help me - PaskaV - 17.01.2016

Hey, i want to ask one question. I want to made a /leavejob <reason>

And i want to write all server job's(where i'm join): Name_SubName leave job reason: test.

This code:

Код:
CMD:leavejob(playerid, params[])
{
	new reason,STRING[150];
    if(sscanf(params, "u", reason)) return SendClientMessage(playerid, COLOR_RED, "* Using: /leavejob [reason]");
    
    if(spec[ playerid ] == 0) return SendClientMessage(playerid, COLOR_RED, "* Nothing to leave");
    if(spec[ playerid] == POLICE)
    {
    format(String[ playerid ], 150,"%s leave job reason: %s",GetPlayerNameEx[playerid], reason);
    SendMessageToPolice( playerid, COLOR_ORANGE,String[ playerid ]);
    }
    else if(spec[ playerid ] == MEDIC)
    {
        format(STRING,128,"%s leave job reason:%s", GetPlayerNameEx[ playerid ], reason);
        SendMessageToMedics( playerid, COLOR_ORANGE,String[ playerid ]);
    }
    SetPlayerSkin( playerid, UNIFORMS[ playerid ] );
    spec[ playerid ]=0;
    UNIFORMA[ playerid ]=-1;
    UNIFORMD[ playerid ]=false;
    GIVEPLAYERCOLORFROMFROFFESION( playerid );
    SetPlayerSkin( playerid, UNIFORMS[ playerid ] );
    UNIFORMD[ playerid ] = false;
    ApplyAnimation(playerid,"PLAYIDLES","stretch",4.1,0,0,0,0,0);
    SendClientMessage(playerid,COLOR_RED,"* Leaved");
	ZERORANGS( playerid );
	return 1;
}
AND when i write /leavejob test he said Nick_Subname leave job reason: 65535 or nothing.


Re: Bad code, help me - Pottus - 17.01.2016

Pottus here long time SA-MP fan retired from doing anything serious you seem to suffer from DISS (Downloaded Idiot Scripting Syndrome) this is a common ailment for many people symptoms include the follow.

- In ability to operate a SA-MP server competently
- Lack of understanding of common errors
- Lack of understanding of common coding practices
- Lack of known SA-MP related functions / callbacks
- Persistent questioning on the forum of code that was not written by ones self

If you demonstrate any or more of the above symptoms you are highly advised to immediately visit the tutorial section in which you will find a plethora of information that will equip you to handle such trivial problems such as the one you have posted.


Re: Bad code, help me - PaskaV - 17.01.2016

Quote:
Originally Posted by Pottus
Посмотреть сообщение
Pottus here long time SA-MP fan retired from doing anything serious you seem to suffer from DISS (Downloaded Idiot Scripting Syndrome) this is a common ailment for many people symptoms include the follow.

- In ability to operate a SA-MP server competently
- Lack of understanding of common errors
- Lack of understanding of common coding practices
- Lack of known SA-MP related functions / callbacks
- Persistent questioning on the forum of code that was not written by ones self

If you demonstrate any or more of the above symptoms you are highly advised to immediately visit the tutorial section in which you will find a plethora of information that will equip you to handle such trivial problems such as the one you have posted.
Ye okey, bye.

Any help?


Respuesta: Re: Bad code, help me - IzadorO - 17.01.2016

https://sampwiki.blast.hk/wiki/Sscanf
https://sampwiki.blast.hk/wiki/Sscanf_code

The 'u' parameter is used for finding a name / id which is connected to the server, and it is returning 65535 (INVALID_PLAYER_ID) because the input did not match any connected name / identities.

Change 'u' to 's[128]', and change reason, to reason[128],

Reason being, 's' indicates a string, and it seems like you want to use a formatted one as the variable is titled 'reason'.

You should definitely read the wiki before proceeding with scripting.

Alternatively, you could forget sscanf for now, and just use 'params'.

Example:

Код:
CMD:leavejob(playerid, params[])
{
     static
        string[128];
    
     if(isnull(params))
        return SendClientMessage(...);

     format(string, sizeof(string), "%s has left their job. Reason: %s"...., params);
     // rest of code.
}