Problem with my /give cmd -
BizzyD - 08.05.2011
Hello, I got a problem with my /give command. When i do /give 2 (someones id) firematches. It says i give them to the npc. Tom_Weaver hands some matches to intro(npc name).
So how do i fix this?
So i can give the player the things i want, And not only the npc.
this is my /give cmd:
pawn Код:
CMD: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));
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
new Float:tx,Float:ty,Float:tz;
GetPlayerPos(targetid,tx,ty,tz);
if(sscanf(params, "us[128]", targetid, option))
{
SendClientMessage(playerid, RED, "[LOST:RP] /give [ID] [OPTION");
SendClientMessage(playerid, COLOR_WHITE, "[LOST:RP] Options: Matches,Firewood,WaterBottle,FishingRod,FishingNet,Heroin");
return 1;
}
if(IsPlayerInRangeOfPoint(playerid, 2.0, tx,ty,tz))
{
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");
}
}
else
{
SendClientMessage(playerid, RED, "[LOST:RP] You are not near anybody");
}
}
}
return 1;
}
Regards, Alex
Re: Problem with my /give cmd -
BizzyD - 08.05.2011
Anyone know how to fix this?
Re: Problem with my /give cmd -
Elka_Blazer - 08.05.2011
where is the strcmp for the option to the "firematches"
Re: Problem with my /give cmd -
BizzyD - 08.05.2011
I dont know.
https://sampforum.blast.hk/showthread.php?tid=253755 This is where i first got my help in this command. But i posted it last night
Re: Problem with my /give cmd -
MadeMan - 08.05.2011
pawn Код:
CMD:give(playerid, params[])
{
new targetid, option[16], string[128];
if(sscanf(params, "us[16]", targetid, option))
{
SendClientMessage(playerid, RED, "[LOST:RP] /give [ID] [OPTION");
SendClientMessage(playerid, COLOR_WHITE, "[LOST:RP] Options: Matches,Firewood,WaterBottle,FishingRod,FishingNet,Heroin");
return 1;
}
new targetname[MAX_PLAYER_NAME], sendername[MAX_PLAYER_NAME];
GetPlayerName(targetid, targetname, sizeof(targetname));
GetPlayerName(playerid, sendername, sizeof(sendername));
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
new Float:tx,Float:ty,Float:tz;
GetPlayerPos(targetid,tx,ty,tz);
...
Re: Problem with my /give cmd -
Elka_Blazer - 08.05.2011
"us[128]",
your option size is 16
by the way , "u" applys for bots and npc too .. you can try r. but I dont think its because of that.
Re: Problem with my /give cmd -
MadeMan - 08.05.2011
Problem is, that sscanf must come before GetPlayerName.
Re: Problem with my /give cmd -
Elka_Blazer - 08.05.2011
Also true .
I also suggest you to use GetName and not GetPlayerName
pawn Код:
stock GetName(playerid)
{
new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid,PlayerName,sizeof(PlayerName));
return PlayerName;
}
Re: Problem with my /give cmd -
BizzyD - 08.05.2011
Is this right?
pawn Код:
CMD:give(playerid, params[])
{
new targetid, option[128], string[128];
if(sscanf(params, "us[128]", targetid, option))
{
SendClientMessage(playerid, RED, "[LOST:RP] /give [ID] [OPTION");
SendClientMessage(playerid, COLOR_WHITE, "[LOST:RP] Options: Matches,Firewood,WaterBottle,FishingRod,FishingNet,Heroin");
return 1;
}
new targetname[MAX_PLAYER_NAME], sendername[MAX_PLAYER_NAME];
GetPlayerName(targetid, targetname, sizeof(targetname));
GetPlayerName(playerid, sendername, sizeof(sendername));
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
new Float:tx,Float:ty,Float:tz;
GetPlayerPos(targetid,tx,ty,tz);