How do I make this work -
Wizardking - 29.12.2013
I want to make a command where I can /givegun (id) (gun id/gun name) but I don't know how to make it, OnPlayerCommandText won't let me add spaces in the command to do "/givegun minigun" so how would I go about making this? I'm new to scripting and would love some help. Thanks.
Re: How do I make this work -
Twizted - 29.12.2013
Get sscanf and include it below a_samp.
pawn Код:
CMD:givegun(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] < 3) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use that command!");
if(sscanf(params, "ud", target, gun)) return SendClientMessage(playerid, COLOR_GREY, "Usage: /givegun [playerid] [gun]");
if(gun < 1 || gun > 47) return SendClientMessage(playerid, COLOR_GREY, "Invalid weapon ID.");
if(!IsPlayerConnected(target)) return SendClientMessage(playerid, COLOR_GREY, "User is not connected!");
if(gun != 21)
{
GivePlayerWeapon(target, gun, 200); //You can change the ammo from 200 to whatever you wish.
format(string, sizeof(string), "Admin %s has given you a weapon.", GetName(playerid));
SendClientMessage(target, COLOR_GREY, string);
format(string, sizeof(string), "You have given %s a weapon.", GetName(target));
SendClientMessage(playerid, COLOR_GREY, string);
}
return 1;
}
Re: How do I make this work -
Wizardking - 29.12.2013
How can I set it so that you don't need to be admin? And can anyone explain how it works?
Re: How do I make this work -
iZN - 29.12.2013
Quote:
Originally Posted by Wizardking
How can I set it so that you don't need to be admin? And can anyone explain how it works?
|
Please read some tutorial, you are really asking beginners question. If you can see this line:
pawn Код:
if(PlayerInfo[playerid][pAdmin] < 3) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use that command!");
Just remove this?
Re: How do I make this work -
Wizardking - 29.12.2013
Quote:
Originally Posted by iZN
Please read some tutorial, you are really asking beginners question. If you can see this line:
pawn Код:
if(PlayerInfo[playerid][pAdmin] < 3) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use that command!");
Just remove this?
|
Shouldn't COLOR_GREY be defined first before it's added in the script?
AW: Re: How do I make this work -
CutX - 29.12.2013
Quote:
Originally Posted by Wizardking
Shouldn't COLOR_GREY be defined first before it's added in the script?
|
of course,
PHP код:
#define COLOR_GREY 0x8C8C8CFF
but that's just an example code, adding stuff like that isn't necessary
as it's general knowledge
Re: How do I make this work -
Wizardking - 29.12.2013
Quote:
Originally Posted by Twizted
Get sscanf and include it below a_samp.
pawn Код:
CMD:givegun(playerid, params[]) { if(PlayerInfo[playerid][pAdmin] < 3) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use that command!"); if(sscanf(params, "ud", target, gun)) return SendClientMessage(playerid, COLOR_GREY, "Usage: /givegun [playerid] [gun]"); if(gun < 1 || gun > 47) return SendClientMessage(playerid, COLOR_GREY, "Invalid weapon ID."); if(!IsPlayerConnected(target)) return SendClientMessage(playerid, COLOR_GREY, "User is not connected!"); if(gun != 21) { GivePlayerWeapon(target, gun, 200); //You can change the ammo from 200 to whatever you wish. format(string, sizeof(string), "Admin %s has given you a weapon.", GetName(playerid)); SendClientMessage(target, COLOR_GREY, string); format(string, sizeof(string), "You have given %s a weapon.", GetName(target)); SendClientMessage(playerid, COLOR_GREY, string); } return 1; }
|
I removed the first line allowing people who aren't admins can give guns, edited the ammo amount and changed the color of the text.
I tried to compile it but it's saying "undefined symbol", these are the errors:
Re: How do I make this work -
Threshold - 29.12.2013
Yes, the second poster has either scripted the code mindlessly without testing it first, or copied it from other script, which shows a lack of effort and a prospering laze in my opinion.
pawn Код:
CMD:givegun(playerid, params[])
{
new targetid, weaponid;
if(sscanf(params, "ui", targetid, weaponid)) return SendClientMessage(playerid, -1, "Usage: /givegun [name/id] [gun]");
if(weaponid < 0 || (weaponid > 18 && weaponid < 22) || weaponid > 46) return SendClientMessage(playerid, -1, "Invalid weapon ID.");
//I was going to create a function like IsValidWeapon, but I think it may cause more confusion for new scripters.
if(!IsPlayerConnected(targetid) || targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "User is not connected!");
GivePlayerWeapon(targetid, weaponid, 200); //You can change the ammo from 200 to whatever you wish.
if(targetid == playerid) return SendClientMessage(playerid, 0xFFFF00FF, "You have given yourself a weapon.");
SendClientMessage(playerid, 0xFFFF00FF, "You have given a weapon to another player."); //Putting a player name/id here is optional.
SendClientMessage(targetid, 0xFFFF00FF, "You have been given a weapon by another player."); //Putting a player name/id here is optional.
return 1;
}
Re: How do I make this work -
Wizardking - 29.12.2013
Quote:
Originally Posted by BenzoAMG
Yes, the second poster has either scripted the code mindlessly without testing it first, or copied it from other script, which shows a lack of effort and a prospering laze in my opinion.
pawn Код:
CMD:givegun(playerid, params[]) { new targetid, weaponid; if(sscanf(params, "ui", targetid, weaponid)) return SendClientMessage(playerid, -1, "Usage: /givegun [name/id] [gun]"); if(weaponid < 0 || (weaponid > 18 && weaponid < 22) || weaponid > 46) return SendClientMessage(playerid, -1, "Invalid weapon ID."); //I was going to create a function like IsValidWeapon, but I think it may cause more confusion for new scripters. if(!IsPlayerConnected(targetid) || targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "User is not connected!"); GivePlayerWeapon(targetid, weaponid, 200); //You can change the ammo from 200 to whatever you wish. if(targetid == playerid) return SendClientMessage(playerid, 0xFFFF00FF, "You have given yourself a weapon."); SendClientMessage(playerid, 0xFFFF00FF, "You have given a weapon to another player."); //Putting a player name/id here is optional. SendClientMessage(targetid, 0xFFFF00FF, "You have been given a weapon by another player."); //Putting a player name/id here is optional. return 1; }
|
Thank you so much, this worked, I appreciate it. +rep