SA-MP Forums Archive
if command successed - 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: if command successed (/showthread.php?tid=370770)



if command successed - Opah - 21.08.2012

i have a cmd that if succeeded it sends a client message else another message
pawn Код:
COMMAND:sync(playerid, params[])
{
    if(!IsPlayerInAnyVehicle(playerid)) {
        new Float:x,Float:y,Float:z,intid,worldid;
        new weaponsQ[MAX_PLAYERS][13][2];
        GetPlayerPos(playerid,x,y,z);
        intid = GetPlayerInterior(playerid);
        worldid = GetPlayerVirtualWorld(playerid);
        ClearAnimations(playerid);
        SetPlayerSpecialAction(playerid,SPECIAL_ACTION_NONE);
        for (new i = 0; i < 13; i++) {
            GetPlayerWeaponData(playerid,i,weaponsQ[playerid][i][0],weaponsQ[playerid][i][1]);
        }
        SpawnPlayer(playerid);
        SetPlayerPos(playerid,x,y,z);
        SetPlayerInterior(playerid,intid);
        SetPlayerVirtualWorld(playerid,worldid);
        for (new i = 0; i < 13; i++) {
            GivePlayerWeapon(playerid,weaponsQ[playerid][i][0],weaponsQ[playerid][i][1]);
        }
        TogglePlayerControllable(playerid,1);
        if(success) {
            SendClientMessage(playerid,COLOR_GREEN,"success");
        }
        else {
            SendClientMessage(playerid,COLOR_GREEN,"fail");
        }
    }
    else {
        new Float:x2,Float:y2,Float:z2,intid2,worldid2,vehicleid2;
        new weaponsQ2[MAX_PLAYERS][13][2];
        vehicleid2 = GetPlayerVehicleID(playerid);
        GetVehiclePos(vehicleid2,x,y,z);
        intid2 = GetPlayerInterior(playerid);
        worldid2 = GetPlayerVirtualWorld(playerid);
        ClearAnimations(playerid);
        SetPlayerSpecialAction(playerid,SPECIAL_ACTION_NONE);
        for (new i = 0; i < 13; i++) {
            GetPlayerWeaponData(playerid,i,weaponsQ2[playerid][i][0],weaponsQ[playerid][i][1]);
        }
        SetVehicleToRespawn(vehicleid2);
        SetVehiclePos(vehicleid2,x2,y2,z2);
        LinkVehicleToInterior(vehicleid2,intid2);
        SetVehicleVirtualWorld(vehicleid2,worldid2);
        for (new i = 0; i < 13; i++) {
            GivePlayerWeapon(playerid,weaponsQ2[playerid][i][0],weaponsQ[playerid][i][1]);
        }
        TogglePlayerControllable(playerid,1);
        if(success) {
            SendClientMessage(playerid,COLOR_GREEN,"success");
        }
        else {
            SendClientMessage(playerid,COLOR_GREEN,"fail");
        }
    }
}



Re: if command successed - Ranama - 21.08.2012

Cool command, what's the problem?


Re: if command successed - Opah - 21.08.2012

need a succes as a param sucess is undefined


Re: if command successed - Ranama - 21.08.2012

If you mean like error message if the player type a command that don't exist try using this, that's what i use (I'm using YCMD):
Код:
public OnPlayerCommandPerformed(playerid, cmdtext[], success){
if(success == 0)return SendClientMessage(playerid, COLOR_GRAY2, "SERVER: Unknown command, use /help for further help.");//If player writes command wrong this will still return it as a true.
}
Hope it helped, otherwise describe more thanks


Re: if command successed - Opah - 21.08.2012

nah u got me wrong
this cmd is designed to c if the player is desynced or not
so if he is decynced his health will appear to us not reducing so i dont ban him for hh only reconnect him


Re: if command successed - Ranama - 21.08.2012

if you want to use this:
Код:
if(success) {
            SendClientMessage(playerid,COLOR_GREEN,"success");
        }
        else {
            SendClientMessage(playerid,COLOR_GREEN,"fail");
        }
You'll have to define a variable like this:
Код:
//this goes into your command start
new success;
//and then you just set this variable to 1 or 0 depending on how the command performed, or you could just send the message directly if it fails or succed.
success = 1;//if it succeded or:
success = 0;//if not
I don't realy get what you are trying to do, but basic you could just send a message if it succeed or not, just like:

Код:
//lets say it succeded here.
SendCleientMessage(playerid, -1, "Success");

//and in this part it didn't succed:
SendCleientMessage(playerid, -1, "Failure");
I don't really get the problem, do you want to like /sync [playerid] and check if another player is synced or do you want to do it on yourself? if you want to check another player then you'll have to use sscanf.
Anyway hope it helped.