Ammo script
#1

Hello guys, i'm currently starting to script and i'm having trouble with the CMD (ZCMD), i actually tried to make these script into ZCMD and add it on my GM:

Код:
dcmd_shareammo(playerid, params[])
{
    new id, ammound, wid;
    if(sscanf(params, "ud", id, ammound)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/shareammo [ID/NAME] [AMMOUND]\"");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000AA, "Player not found");
    if((wid = GetPlayerWeapon(playerid)) && 43 >= wid >= 16) return SendClientMessage(playerid, 0x00FF00AA, "Acquire a right weapon");
    if(GetPlayerAmmo(playerid) < ammound) return SendClientMessage(playerid, 0x00FF00AA, "You dont have that much ammo");
    new string[128];
    format(string, sizeof string, "You got %d ammo ", ammound);
    SendClientMessage(id, 0x00FF00AA, string);
    format(string, sizeof string, "You gived %d ammo", ammound);
    SendClientMessage(playerid, 0x00FF00AA, string);
    wid = GetPlayerWeapon(playerid);
    GivePlayerWeapon(playerid, wid, -ammound);
    GivePlayerWeapon(id, wid, ammound);
    return 1;
}
Код:
CMD:shareammo(playerid, params[])
{
    new id, ammound, wid;
    if(sscanf(params, "ud", id, ammound)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/shareammo [ID/NAME] [AMMOUND]\"");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000AA, "Player not found");
    if((wid = GetPlayerWeapon(playerid)) && 43 >= wid >= 16) return SendClientMessage(playerid, 0x00FF00AA, "Acquire a right weapon");
    if(GetPlayerAmmo(playerid) < ammound) return SendClientMessage(playerid, 0x00FF00AA, "You dont have that much ammo");
    new string[128];
    format(string, sizeof string, "You got %d ammo ", ammound);
    SendClientMessage(id, 0x00FF00AA, string);
    format(string, sizeof string, "You gived %d ammo", ammound);
    SendClientMessage(playerid, 0x00FF00AA, string);
    wid = GetPlayerWeapon(playerid);
    GivePlayerWeapon(playerid, wid, -ammound);
    GivePlayerWeapon(id, wid, ammound);
    return 1;
}
Reply
#2

Make sure that ZCMD command is outside of OnPlayerCommandText. ZCMD has to be outside all functions, you can add it to the end of your GM.
Reply
#3

What's the problem with it?
Reply
#4

Quote:
Originally Posted by Dan.
Посмотреть сообщение
Make sure that ZCMD command is outside of OnPlayerCommandText. ZCMD has to be outside all functions, you can add it to the end of your GM.
I though i had to add it inside OnPlayerCommandText, like the other type of codings strcmp,DCMD_ etc, thanks Dan, i'll check it out.

Was giving me invalid function or declaration, but it's fixed, Thanks guy you can close the thread now.
Reply
#5

I didn't test it today as i went to the school, so here it is the code as i used:

Код:
CMD:giveammo(playerid, params[]) 
{
    new id, ammound, wid;
    if(sscanf(params, "ud", id, ammound)) return SendClientMessage(playerid, 0xAFAFAFAA, "Usage: \"/giveammo [id/name] [ammount]\"");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xAFAFAFAA, "Player not found");
    if((wid = GetPlayerWeapon(playerid)) && 43 >= wid >= 16) return SendClientMessage(playerid, 0x00FF00AA, "Acquire a right weapon");
    if(GetPlayerAmmo(playerid) < ammound) return SendClientMessage(playerid, 0xAFAFAFAA, "You dont have that much ammo");
    new string[128];
    format(string, sizeof string, "You got %d ammo ", ammound);
    SendClientMessage(id, 0x00FF00AA, string);
    format(string, sizeof string, "You gived %d ammo", ammound);
    SendClientMessage(playerid, 0x00FF00AA, string);
    wid = GetPlayerWeapon(playerid);
    GivePlayerWeapon(playerid, wid, -ammound);
    GivePlayerWeapon(id, wid, ammound);
    return 1;
}
It's not letting me give ammo to someone carrying the same gun, even if i have the more bullets than what i'm giving or the other player having the same gun as i do it just drops me the same message "Acquire a right weapon" i tried to check it out plenty of times but for my knowledge the code is fine... i need some help :S
Reply
#6

pawn Код:
CMD:giveammo(playerid, params[])
{
    new id, ammound, wid;
    if(sscanf(params, "ud", id, ammound)) return SendClientMessage(playerid, 0xAFAFAFAA, "Usage: \"/giveammo [id/name] [ammount]\"");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xAFAFAFAA, "Player not found");
    if(wid >= 43 || wid <= 16) return SendClientMessage(playerid, 0x00FF00AA, "Acquire a right weapon");
    if(GetPlayerAmmo(playerid) < ammound) return SendClientMessage(playerid, 0xAFAFAFAA, "You dont have that much ammo");
    new string[128];
    format(string, sizeof string, "You got %d ammo ", ammound);
    SendClientMessage(id, 0x00FF00AA, string);
    format(string, sizeof string, "You gived %d ammo", ammound);
    SendClientMessage(playerid, 0x00FF00AA, string);
    wid = GetPlayerWeapon(playerid);
       SetPlayerAmmo(playerid,wid,ammound);
    return 1;
}
try this
Reply
#7

Quote:
Originally Posted by XStormiest
Посмотреть сообщение
pawn Код:
CMD:giveammo(playerid, params[])
{
    new id, ammound, wid;
    if(sscanf(params, "ud", id, ammound)) return SendClientMessage(playerid, 0xAFAFAFAA, "Usage: \"/giveammo [id/name] [ammount]\"");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xAFAFAFAA, "Player not found");
    if(wid >= 43 || wid <= 16) return SendClientMessage(playerid, 0x00FF00AA, "Acquire a right weapon");
    if(GetPlayerAmmo(playerid) < ammound) return SendClientMessage(playerid, 0xAFAFAFAA, "You dont have that much ammo");
    new string[128];
    format(string, sizeof string, "You got %d ammo ", ammound);
    SendClientMessage(id, 0x00FF00AA, string);
    format(string, sizeof string, "You gived %d ammo", ammound);
    SendClientMessage(playerid, 0x00FF00AA, string);
    wid = GetPlayerWeapon(playerid);
       SetPlayerAmmo(playerid,wid,ammound);
    return 1;
}
try this
It's not taking any effect, i'm not sure what's wrong with this code, anyone got ideas? i'm a basic scripter so it's out of my knowledge, can someone help me around here.


Ok i found the problem, pretty sure it's not working due to i haven't converted it to zcmd, but i'm kinda new to zcmd so i'm not sure

On TOP
Код:
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
public OnPlayerCommandText(playerid, cmdtext[])
Код:
dcmd(shareammo, 9, cmdtext);
public OnPlayerCommandText(playerid,cmdtext[]) (converted to ZCMD, not sure if it's right)
Код:
zcmd(shareammo, 9, cmdtext);
[pwn]CMD:giveammo(playerid, params[])
{
new id, ammound, wid;
if(sscanf(params, "ud", id, ammound)) return SendClientMessage(playerid, 0xAFAFAFAA, "Usage: \"/giveammo [id/name] [ammount]\"");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xAFAFAFAA, "Player not found");
if(wid >= 43 || wid <= 16) return SendClientMessage(playerid, 0x00FF00AA, "Acquire a right weapon");
if(GetPlayerAmmo(playerid) < ammound) return SendClientMessage(playerid, 0xAFAFAFAA, "You dont have that much ammo");
new string[128];
format(string, sizeof string, "You got %d ammo ", ammound);
SendClientMessage(id, 0x00FF00AA, string);
format(string, sizeof string, "You gived %d ammo", ammound);
SendClientMessage(playerid, 0x00FF00AA, string);
wid = GetPlayerWeapon(playerid);
SetPlayerAmmo(playerid,wid,ammound);
return 1;
}[/pawn]

Help?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)