[Help] About Making Commands "TMP"
#5

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 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
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
Reply


Messages In This Thread
[Help] About Making Commands "TMP" - by Justin-Curry - 11.02.2011, 16:39
Re : [Help] About Making Commands "TMP" - by Justin-Curry - 11.02.2011, 17:48
Re: [Help] About Making Commands "TMP" - by omer5198 - 11.02.2011, 17:54
Re : [Help] About Making Commands "TMP" - by Justin-Curry - 11.02.2011, 18:19
Re: [Help] About Making Commands "TMP" - by omer5198 - 13.02.2011, 12:17

Forum Jump:


Users browsing this thread: 6 Guest(s)