[Help] About Making Commands "TMP" - 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: [Help] About Making Commands "TMP" (
/showthread.php?tid=224366)
[Help] About Making Commands "TMP" -
Justin-Curry - 11.02.2011
Hello, well im looking for Help from someone that can teach me TMP or how to do the /xx zzzzz Commands style
Like When player dont type it good, Correct usage is /xx zzzzz
Anyway i know that have relation with Tmp so could anyone explain me please?
Re : [Help] About Making Commands "TMP" -
Justin-Curry - 11.02.2011
Thanks Lot Bro, but would you give me an example of
/getweapon [Name Of weapon]
A Full code with some explanations if you can please, using strcmp and SScanf
If you couldnt be busy, may you give me an example of /makeadmin [Playerid] too?
Thanks anyway for teh previous explanation
Re: [Help] About Making Commands "TMP" -
omer5198 - 11.02.2011
you will need strtok include for this command...
![Sad](images/smilies/sad.gif)
the command is /giveweapon [weaponid] [ammo])
PHP код:
public OnPlayerCommandText(playerid, cmdtext[])
{
new idx;
new cmd[256];
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/giveweapon", true) == 0) {
new tmp[256],tmp2[256],tmp3[256];
tmp = strtok(cmdtext, idx);
tmp2 = strtok(cmdtext, idx);
tmp3 = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, COLOUR_ORANGE, "Usage : /giveweapon [playerid] [weaponid] [amount]");
return 1;
}
if(!strlen(tmp2)) {
SendClientMessage(playerid, COLOUR_ORANGE, "Usage : /giveweapon [playerid] [weaponid] [amount]");
return 1;
}
if(!strlen(tmp3)) {
SendClientMessage(playerid, COLOUR_ORANGE, "Usage : /giveweapon [playerid] [weaponid] [amount]");
return 1;
}
new victim, weaponid, ammo;
victim = strval(tmp);
weaponid = strval(tmp2);
ammo = strval(tmp3);
new string[128];
new playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
new playername2[MAX_PLAYER_NAME];
GetPlayerName(victim, playername2, sizeof(playername2));
format(string, sizeof(string), "The admin %s gave you a weapon.", playername);
SendClientMessage(victim, COLOUR_YELLOW, string);
GivePlayerWeapon(victim, weaponid, ammo);
format(string, sizeof(string), "you gave %s a weapon.", playername2);
SendClientMessage(playerid, COLOUR_YELLOW, string);
return 1;
}
Re : [Help] About Making Commands "TMP" -
Justin-Curry - 11.02.2011
Thanks Lot Bro!!
Re: [Help] About Making Commands "TMP" -
omer5198 - 13.02.2011
Quote:
Originally Posted by [HLF]Southclaw
@omer5198: Read what I said before:
If you are using STRTOK then stop using it. It is slow, out of date and everyone says it's bad so I have no idea why it's still on SA:MP Wiki.
Ok, a getweapon command is pretty much the same as what I wrote earlier.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[]) { new cmd[30], params[100]; sscanf(cmdtext, "s[30]s[100]", cmd, params); if(!strcmp(cmd, "/getweapon")) { new id = strval(params); // Right here the ID doesn't just have to be a playerid // remember pretty much everything in SA:MP is represented by numbers, playerids, cars, weapons etc // This basic command is pretty much: '/command <number>' [without the '<' and '>' obviously] // So 'params' is just whatever text the player types after a space in the command. // And in this example we use 'strval' to convert that string to a number so it can be used in functions that require 'ID' numbers // Such as player ids, weapon models, vehicle models, any data that is represented by a number in function parameters.
// So you now have your 'id' variable that represents a weapon ID, you now use the variable in the function GivePlayerWeapon, which uses 'weaponid' as a parameter:
GivePlayerWeapon(playerid, id, 10000); // 'playerid' = player who typed command, 'id' = weapon id they entered after the command //[referred to as a 'parameter', similar concept to how functions have parameters, but this is for in-game commands.] return 1; } }
There, that command should work, it will give the player who entered it whatever weapon ID they type with 10000 ammo.
For instance, if player 3 entered '/getweapon 34' it will give player 4 a sniper rifle [id 34] with 10000 bullets
And in the script the function GivePlayerWeapon will be executed [scripting term that basically means when the function is used or 'called'] and the parameters for the function will be set to GetPlayerWeapon(3, 34, 10000); because 'playerid' = 3 [player who entered it] 'id' = 34 [number after the command or 'parameter'] 10000 [which is just in the function anyway]
I hope that helps you understand ![Tongue](images/smilies/razz.gif) if there's anything else that you don't understand I can try and explain it in as much detail as possible so you understand ![Smiley](images/smilies/smile.png)
|
im using it because i don't know how to use something else like the thing that you used and i got no one to teach me