PDA

View Full Version : SSCANF Errors


aoky
03/07/2017, 07:18 PM
CMD:unpackageweapon(playerid, params[])
{
new player, packagetype, str[128];
if(sscanf(params, "su", packagetype, playerid)) return SendClientMessage(playerid, COLOR_GRAY, "/unpackage [playerid] [packagetype]");
{
if(IsInRangeOfPlayer(playerid, player, 5))
{
if(!strcmp(packagetype, "pistol", true))
{
if(Inventory[playerid][PistolPackage] > 0)
{
TakeInventoryItem(playerid, PISTOLPACKAGE, 1);
GivePlayerGun(player, 24, 100);

}
else SendErrorMessage(playerid, "You don't have this item.");
return 1;
}
else if(!strcmp(packagetype, "shotgun", true))
{
if(Inventory[playerid][ShotgunPackage] > 0)
{
TakeInventoryItem(playerid, SHOTGUNPACKAGE, 1);
GivePlayerGun(player, 25, 125);

}
else SendErrorMessage(playerid, "You don't have this item.");
}
else if(!strcmp(packagetype, "automatic", true))
{
if(Inventory[playerid][AutomaticRiflePackage] > 0)
{
TakeInventoryItem(playerid, AUTOMATICRIFLEPACKAGE, 1);
format(str, sizeof(str), "%s hands an M4 to %s. ", GetRoleplayName(playerid), GetRoleplayName(player));
SetPlayerChatBubble(playerid, str, COLOR_RP, Range_Short, 7000);
GivePlayerGun(player, 31, 250);
}
else if(!strcmp(packagetype, "molotov", true))
{
if(Inventory[playerid][ExplosivePackage] > 0)
{
TakeInventoryItem(playerid, EXPLOSIVEPACKAGE, 1);
format(str, sizeof(str), "%s hands a Molotov %s. ", GetRoleplayName(playerid), GetRoleplayName(player));
SetPlayerChatBubble(playerid, str, COLOR_RP, Range_Short, 7000);
GivePlayerGun(player, 18, 1);
}
else SendErrorMessage(playerid, "You don't have this item.");

return 1;
}
}
}
else SendErrorMessage(playerid, "You are too far away from this player.");

}
return 1;
}


C:\Users\Austin\Desktop\Stuff\United Roleplay\gamemodes\U:RP-R39.pwn(17007) : error 035: argument type mismatch (argument 1)
C:\Users\Austin\Desktop\Stuff\United Roleplay\gamemodes\U:RP-R39.pwn(17018) : error 035: argument type mismatch (argument 1)
C:\Users\Austin\Desktop\Stuff\United Roleplay\gamemodes\U:RP-R39.pwn(17028) : error 035: argument type mismatch (argument 1)
C:\Users\Austin\Desktop\Stuff\United Roleplay\gamemodes\U:RP-R39.pwn(17037) : error 035: argument type mismatch (argument 1


These are the lines, where it has "packagetype". Why is this?


else if(!strcmp(packagetype, "pistol", true))

Kane
03/07/2017, 07:34 PM
Packagetype isn't a string. Make it a string.

Freedom.
03/07/2017, 07:37 PM
CMD:unpackageweapon(playerid, params[])
{
new packagetype[12], player, str[128];

if(sscanf(params, "D(-1)s[12]", player, packagetype))
return SendClientMessage(playerid, COLOR_GRAY, "/unpackage [playerid] [packagetype]");

if(!IsInRangeOfPlayer(playerid, player, 5))
return SendClientMessage(playerid, COLOR_GRAY, "You are too far away from this player.");

if(!strcmp(packagetype, "pistol", true))
{
if(Inventory[playerid][PistolPackage] > 0)
{
TakeInventoryItem(playerid, PISTOLPACKAGE, 1);
GivePlayerGun(player, 24, 100);
}
else SendErrorMessage(playerid, "You don't have this item.");
}
else if(!strcmp(packagetype, "shotgun", true))
{
if(Inventory[playerid][ShotgunPackage] > 0)
{
TakeInventoryItem(playerid, SHOTGUNPACKAGE, 1);
GivePlayerGun(player, 25, 125);
}
else SendErrorMessage(playerid, "You don't have this item.");
}
else if(!strcmp(packagetype, "automatic", true))
{
if(Inventory[playerid][AutomaticRiflePackage] > 0)
{
TakeInventoryItem(playerid, AUTOMATICRIFLEPACKAGE, 1);
format(str, sizeof(str), "%s hands an M4 to %s. ", GetRoleplayName(playerid), GetRoleplayName(player));
SetPlayerChatBubble(playerid, str, COLOR_RP, Range_Short, 7000);
GivePlayerGun(player, 31, 250);
}
else SendErrorMessage(playerid, "You don't have this item.");
}
else if(!strcmp(packagetype, "molotov", true))
{
if(Inventory[playerid][ExplosivePackage] > 0)
{
TakeInventoryItem(playerid, EXPLOSIVEPACKAGE, 1);
format(str, sizeof(str), "%s hands a Molotov %s. ", GetRoleplayName(playerid), GetRoleplayName(player));
SetPlayerChatBubble(playerid, str, COLOR_RP, Range_Short, 7000);
GivePlayerGun(player, 18, 1);
}
else SendErrorMessage(playerid, "You don't have this item.");
}
return 1;
}

Kane
03/07/2017, 07:40 PM
Why would you use D(-1) for playerid Freedom?

Freedom.
03/07/2017, 07:55 PM
Check for is player id entered:

else if(!strcmp(packagetype, "select", true))
{
if(player == -1)
return SendClientMessage(playerid, COLOR_GRAY, "/unpackage select <player ID>");

if(!IsPlayerConnected(player))
return SendClientMessage(playerid, COLOR_GRAY, "id not found");

// ...

return 1;
}

Kane
03/07/2017, 08:08 PM
But why would you do that when you could just use the user specifier for playerid OR name?

aoky
03/07/2017, 08:19 PM
It works and that's all that matters, everyone has their own style of coding. Thank you.