SA-MP Forums Archive
Problem with /give cmd - 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: Problem with /give cmd (/showthread.php?tid=253755)



Problem with /give cmd - BizzyD - 07.05.2011

Hello. I am currently scripting a /give command. And i dont know how to do it in ZCMD + SSCANF.

This is what i got so far:

pawn Код:
CMD:give(playerid,params[])
{
    new giveplayerid;
    new giveplayer[MAX_PLAYER_NAME];
    new sendername[MAX_PLAYER_NAME];
    new option[256];
    if(sscanf(params, "u", giveplayer))
    return SendClientMessage(playerid, RED, "[LOST:RP] /give [ID] [OPTION");
    return SendClientMessage(playerid, RED, "[LOST:RP] Options: Matches,Firewood,WaterBottle,FishingRod,FishingNet,Heroin");
    if(giveplayerid == playerid)
    return SendClientMessage(playerid, RED, "[LOST:RP] You cant give yourself stuff");
    {
        if(params(option,"Matches",true) == 0)
        {
            if(PlayerInfo[playerid][pMatches] > 0)
            {
                GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                GetPlayerName(playerid, sendername, sizeof(sendername));
                PlayerInfo[playerid][pMatches] -= 1;
                PlayerInfo[giveplayer][pMatches] += 1;
                format(string, sizeof(string), "%s hands some matches to %s", sendername,giveplayer);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have any matches to give");
            }
        }
        if(params(option,"Firewood",true) == 0)
        {
            if(PlayerInfo[playerid][pWood] > 0)
            {
                GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                GetPlayerName(playerid, sendername, sizeof(sendername));
                PlayerInfo[playerid][pWood] -= 1;
                PlayerInfo[giveplayer][pWood] += 1;
                format(string, sizeof(string), "%s hands fire wood to %s", sendername,giveplayer);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have any firewoods to give");
            }
        }
        if(params(option,"WaterBottle",true) == 0)
        {
            if(PlayerInfo[playerid][pWaterBottle] > 0)
            {
                GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                GetPlayerName(playerid, sendername, sizeof(sendername));
                PlayerInfo[playerid][pWaterBottle] -= 1;
                PlayerInfo[giveplayer][pWaterBottle] += 1;
                format(string, sizeof(string), "%s hands a WaterBottle to %s", sendername,giveplayer);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have any WaterBottles");
            }
        }
        if(params(option,"FishingRod",true) == 0)
        {
            if(PlayerInfo[playerid][pFishingRod] > 0)
            {
                GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                GetPlayerName(playerid, sendername, sizeof(sendername));
                PlayerInfo[playerid][pFishingRod] -= 1;
                PlayerInfo[giveplayer][FishingRod] += 1;
                format(string, sizeof(string), "%s hands a Fishing Rod to %s", sendername,giveplayer);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have a Fishing Rod");
            }
        }
        if(params(option,"FishingNet",true) == 0)
        {
            if(PlayerInfo[playerid][pFishingNet] > 0)
            {
                GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                GetPlayerName(playerid, sendername, sizeof(sendername));
                PlayerInfo[playerid][pFishingNet] -= 1;
                PlayerInfo[giveplayer][pFishingNet] += 1;
                format(string, sizeof(string), "%s hands a Fishing Net to %s", sendername,giveplayer);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have a Fishing Net");
            }
        }
        if(params(option,"Heroin",true) == 0)
        {
            if(PlayerInfo[playerid][pHeroin] > 0)
            {
                GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                GetPlayerName(playerid, sendername, sizeof(sendername));
                PlayerInfo[playerid][pHeroin] -= 1;
                PlayerInfo[giveplayer][pHeroin] += 1;
                format(string, sizeof(string), "%s hands a bag of heroin to %s", sendername,giveplayer);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have any heroin");
            }
        }
        return 1;
    }
}
And i get all this errors:

Код:
(2665) : warning 225: unreachable code
(2668) : error 012: invalid function call, not a valid address
(2668) : warning 215: expression has no effect
(2668) : warning 215: expression has no effect
(2668) : warning 215: expression has no effect
(2668) : error 001: expected token: ";", but found ")"
(2668) : error 029: invalid expression, assumed zero
(2668) : fatal error 107: too many error messages on one line
Line 2665:
Код:
CMD:give(playerid,params[])
Line 2668:

Код:
if(params(option,"Matches",true) == 0)
How do i solve this?


Re: Problem with /give cmd - Laronic - 07.05.2011

Not tested
pawn Код:
COMMAND:give(playerid, params[])
{
    new targetid, option[15];
    new targetname[MAX_PLAYER_NAME], sendername[MAX_PLAYER_NAME];
    GetPlayerName(targetid, targetname, sizeof(targetname));
    GetPlayerName(playerid, sendername, sizeof(sendername));
    if(sscanf(params, "us[128]", targetid, option))
    {
        SendClientMessage(playerid, RED, "[LOST:RP] /give [ID] [OPTION");
        SendClientMessage(playerid, RED, "[LOST:RP] Options: Matches,Firewood,WaterBottle,FishingRod,FishingNet,Heroin");
    }
    if(targetid == playerid) return SendClientMessage(playerid, RED, "[LOST:RP] You cant give yourself stuff");
    {
        if(!strfind(option, "Matches", false))
        {
            if(PlayerInfo[playerid][pMatches] > 0)
            {
                PlayerInfo[playerid][pMatches] -= 1;
                PlayerInfo[targetname][pMatches] += 1;
                format(string, sizeof(string), "%s hands some matches to %s", sendername,targetname);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have any matches to give");
            }
        }
        if(!strfind(option, "Firewood", false))
        {
            if(PlayerInfo[playerid][pWood] > 0)
            {
                PlayerInfo[playerid][pWood] -= 1;
                PlayerInfo[targetname][pWood] += 1;
                format(string, sizeof(string), "%s hands fire wood to %s", sendername,targetname);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have any firewoods to give");
            }
        }
        if(!strfind(option, "WaterBottle", false))
        {
            if(PlayerInfo[playerid][pWaterBottle] > 0)
            {
                PlayerInfo[playerid][pWaterBottle] -= 1;
                PlayerInfo[targetname][pWaterBottle] += 1;
                format(string, sizeof(string), "%s hands a WaterBottle to %s", sendername,targetname);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have any WaterBottles");
            }
        }
        if(!strfind(option, "FishingRod", false))
        {
            if(PlayerInfo[playerid][pFishingRod] > 0)
            {
                PlayerInfo[playerid][pFishingRod] -= 1;
                PlayerInfo[targetname][FishingRod] += 1;
                format(string, sizeof(string), "%s hands a Fishing Rod to %s", sendername,targetname);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have a Fishing Rod");
            }
        }
        if(!strfind(option, "FishingNet", false))
        {
            if(PlayerInfo[playerid][pFishingNet] > 0)
            {
                PlayerInfo[playerid][pFishingNet] -= 1;
                PlayerInfo[targetname][pFishingNet] += 1;
                format(string, sizeof(string), "%s hands a Fishing Net to %s", sendername,targetname);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have a Fishing Net");
            }
        }
        if(!strfind(option, "Heroin", false))
        {
            if(PlayerInfo[playerid][pHeroin] >= 0)
            {
                PlayerInfo[playerid][pHeroin] -= 1;
                PlayerInfo[targetname][pHeroin] += 1;
                format(string, sizeof(string), "%s hands a bag of heroin to %s", sendername,targetname);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have any heroin");
            }
        }
        return 1;
    }
}



Re: Problem with /give cmd - BizzyD - 07.05.2011

Код:
C:\Users\Alex\Desktop\Lost Roleplay\gamemodes\lost.pwn(2674) : error 033: array must be indexed (variable "targetname")
C:\Users\Alex\Desktop\Lost Roleplay\gamemodes\lost.pwn(2688) : error 033: array must be indexed (variable "targetname")
C:\Users\Alex\Desktop\Lost Roleplay\gamemodes\lost.pwn(2702) : error 033: array must be indexed (variable "targetname")
C:\Users\Alex\Desktop\Lost Roleplay\gamemodes\lost.pwn(2716) : error 033: array must be indexed (variable "targetname")
C:\Users\Alex\Desktop\Lost Roleplay\gamemodes\lost.pwn(2730) : error 033: array must be indexed (variable "targetname")
C:\Users\Alex\Desktop\Lost Roleplay\gamemodes\lost.pwn(2744) : error 033: array must be indexed (variable "targetname")
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase



Re: Problem with /give cmd - Laronic - 07.05.2011

pawn Код:
PlayerInfo[targetname][pMatches] += 1;
//Should be
PlayerInfo[targetid][pMatches] += 1;


PlayerInfo[targetname][pWood] += 1;
//Should be
PlayerInfo[targetid][pWood] += 1;

//then so on



Re: Problem with /give cmd - BizzyD - 07.05.2011

Thanks works now

Now i just need to find someone to test it with me


Re: Problem with /give cmd - admantis - 07.05.2011

Better if you use strcmp because strfind will allow you to do stuff like

'adskadFireWoodakfk'
'FireWood000d15815'
'000000FireWood15915'

And infinite results and it will still work.
pawn Код:
if (strcmp(option, "ItemName", true) == 0)



Re: Problem with /give cmd - Laronic - 07.05.2011

Quote:
Originally Posted by admantis
Посмотреть сообщение
Better if you use strcmp because strfind will allow you to do stuff like

'adskadFireWoodakfk'
'FireWood000d15815'
'000000FireWood15915'

And infinite results and it will still work.
pawn Код:
if (strcmp(option, "ItemName", true) == 0)
Oh thats true! Thanks


Re: Problem with /give cmd - BizzyD - 07.05.2011

Fixed it Thanks for the tips


Re: Problem with /give cmd - BizzyD - 07.05.2011

Alright i tested it now. And when i only do /give. This is what happends:

the code is:
pawn Код:
COMMAND:give(playerid, params[])
{
    new targetid, option[15], string[128];
    new targetname[MAX_PLAYER_NAME], sendername[MAX_PLAYER_NAME];
    GetPlayerName(targetid, targetname, sizeof(targetname));
    GetPlayerName(playerid, sendername, sizeof(sendername));
    if(sscanf(params, "us[128]", targetid, option))
    {
        SendClientMessage(playerid, RED, "[LOST:RP] /give [ID] [OPTION");
        SendClientMessage(playerid, RED, "[LOST:RP] Options: Matches,Firewood,WaterBottle,FishingRod,FishingNet,Heroin");
    }
    if(targetid == playerid) return SendClientMessage(playerid, RED, "[LOST:RP] You cant give yourself stuff");
    {
        if (strcmp(option, "Matches", true) == 0)
        {
            if(PlayerInfo[playerid][pMatches] > 0)
            {
                PlayerInfo[playerid][pMatches] -= 1;
                PlayerInfo[targetid][pMatches] += 1;
                format(string, sizeof(string), "%s hands some matches to %s", sendername,targetname);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have any matches to give");
            }
        }
        if (strcmp(option, "FireWood", true) == 0)
        {
            if(PlayerInfo[playerid][pWood] > 0)
            {
                PlayerInfo[playerid][pWood] -= 1;
                PlayerInfo[targetid][pWood] += 1;
                format(string, sizeof(string), "%s hands fire wood to %s", sendername,targetname);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have any firewoods to give");
            }
        }
        if (strcmp(option, "WaterBottle", true) == 0)
        {
            if(PlayerInfo[playerid][pWaterBottle] > 0)
            {
                PlayerInfo[playerid][pWaterBottle] -= 1;
                PlayerInfo[targetid][pWaterBottle] += 1;
                format(string, sizeof(string), "%s hands a WaterBottle to %s", sendername,targetname);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have any WaterBottles");
            }
        }
        if (strcmp(option, "FishingRod", true) == 0)
        {
            if(PlayerInfo[playerid][pFishingRod] > 0)
            {
                PlayerInfo[playerid][pFishingRod] -= 1;
                PlayerInfo[targetid][pFishingRod] += 1;
                format(string, sizeof(string), "%s hands a Fishing Rod to %s", sendername,targetname);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have a Fishing Rod");
            }
        }
        if (strcmp(option, "FishingNet", true) == 0)
        {
            if(PlayerInfo[playerid][pFishingNet] > 0)
            {
                PlayerInfo[playerid][pFishingNet] -= 1;
                PlayerInfo[targetid][pFishingNet] += 1;
                format(string, sizeof(string), "%s hands a Fishing Net to %s", sendername,targetname);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have a Fishing Net");
            }
        }
        if (strcmp(option, "Heroin", true) == 0)
        {
            if(PlayerInfo[playerid][pHeroin] >= 0)
            {
                PlayerInfo[playerid][pHeroin] -= 1;
                PlayerInfo[targetid][pHeroin] += 1;
                format(string, sizeof(string), "%s hands a bag of heroin to %s", sendername,targetname);
                ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
            }
            else
            {
                SendClientMessage(playerid, RED, "[LOST:RP] You dont have any heroin");
            }
        }
        return 1;
    }
}



Re: Problem with /give cmd - Laronic - 07.05.2011

pawn Код:
if(sscanf(params, "us[128]", targetid, option))
    {
        SendClientMessage(playerid, RED, "[LOST:RP] /give [ID] [OPTION");
        SendClientMessage(playerid, RED, "[LOST:RP] Options: Matches,Firewood,WaterBottle,FishingRod,FishingNet,Heroin");
        return 1;
    }