CMD:heal(playerid, params[]) // In this case you will have to type /heal in game for this command to work. { new string[128], pID, Float:Health; //We will create a new variable "pID" which will define which player id we want to heal, float variable (tag) to store player's health in and name it "Health" and "string" to format it later and sent formatted messages. if(sscanf(params, "d", pID)) return SendClientMessage(playerid, -1, "USAGE: /heal (playerid)"); //Using "sscanf" we can check if player type "/heal" in chat, this message will pop out, letting him know he has to use /heal (playerid). if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, -1, "That player is not connected."); //Using "!IsPlayerConnected" we check if player (playerid) we are trying to heal is even connected, if not, this message will be sent and command will not be executed. GetPlayerHealth(pID, Health); //Thats the function to get player's health if(Health == 100) return SendClientMessage(playerid, -1, "Player is already full Health."); //With this, we check if player's health is 100, that means he doesnt need to be healed and. SetPlayerHealth(pID, 100.0); format(string, sizeof(string), "You have healed %s (%d).", PlayerName(pID), pID); //Formatting the message, you can checke the specifiers we use in this case on sscanf website I linked above. SendClientMessage(playerid, -1, string); //Sending message format(string, sizeof(string), "You have been healed by %s.", PlayerName(playerid)); //Formatting the message, you can checke the specifiers we use in this case on sscanf website I linked above. SendClientMessage(pID, -1, string); //Sending message return 1; } PlayerName(playerid) { new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name)); return name; }
Well for start (assuming you know how to include includes) I want you to download and include these 2 includes / plugins in your gamemode..
sscanf: https://sampforum.blast.hk/showthread.php?tid=570927 Pawn.CMD: https://sampforum.blast.hk/showthread.php?tid=608474 With these 2 plugins you can create commands.. Here's example Code:
CMD:heal(playerid, params[]) // In this case you will have to type /heal in game for this command to work. { new string[128], pID, Float:Health; //We will create a new variable "pID" which will define which player id we want to heal, float variable (tag) to store player's health in and name it "Health" and "string" to format it later and sent formatted messages. if(sscanf(params, "d", pID)) return SendClientMessage(playerid, -1, "USAGE: /heal (playerid)"); //Using "sscanf" we can check if player type "/heal" in chat, this message will pop out, letting him know he has to use /heal (playerid). if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, -1, "That player is not connected."); //Using "!IsPlayerConnected" we check if player (playerid) we are trying to heal is even connected, if not, this message will be sent and command will not be executed. GetPlayerHealth(pID, Health); //Thats the function to get player's health if(Health == 100) return SendClientMessage(playerid, -1, "Player is already full Health."); //With this, we check if player's health is 100, that means he doesnt need to be healed and. SetPlayerHealth(pID, 100.0); format(string, sizeof(string), "You have healed %s (%d).", PlayerName(pID), pID); //Formatting the message, you can checke the specifiers we use in this case on sscanf website I linked above. SendClientMessage(playerid, -1, string); //Sending message format(string, sizeof(string), "You have been healed by %s.", PlayerName(playerid)); //Formatting the message, you can checke the specifiers we use in this case on sscanf website I linked above. SendClientMessage(pID, -1, string); //Sending message return 1; } PlayerName(playerid) { new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name)); return name; } Behind "//" (comment) I specified what each line does. |
First of all, the language is Pawn and not pawno (pawno is an editor, which uses pawncc as compiler).
You may want to start with this one: https://github.com/compuphase/pawn/b...uage_Guide.pdf Make sure you read this one aswell: https://sampwiki.blast.hk/wiki/Scripting_Basics These tutorials I find pretty important aswell (especially the arrays one): https://sampforum.blast.hk/showthread.php?pid=876854#pid876854 https://sampforum.blast.hk/showthread.php?tid=318212 Apart from that you should just download scripts on the forums here and look into them and try to understand what it does. Then start creating your own stuff. Just play around with coding a bit and see what it does during runtime (tip: Use alot of debugging messages -It tells you exactly what is happening -or not if it does not pop up). Also you might wanna check out the YSI library (look it up). |
Thanks for the help, but can you tell me what did %s %d do? I mean what does the line mean (format,sizeof string) what is sizeof string string? Can you explain that briefly?
Because i can create this command, but not like this and i wanna know like this. Thanks. |
First of all, the language is Pawn and not pawno (pawno is an editor, which uses pawncc as compiler).
You may want to start with this one: https://github.com/compuphase/pawn/b...uage_Guide.pdf Make sure you read this one aswell: https://sampwiki.blast.hk/wiki/Scripting_Basics These tutorials I find pretty important aswell (especially the arrays one): https://sampforum.blast.hk/showthread.php?pid=876854#pid876854 https://sampforum.blast.hk/showthread.php?tid=318212 Apart from that you should just download scripts on the forums here and look into them and try to understand what it does. Then start creating your own stuff. Just play around with coding a bit and see what it does during runtime (tip: Use alot of debugging messages -It tells you exactly what is happening -or not if it does not pop up). Also you might wanna check out the YSI library (look it up). |
I read all the threads, excepts that big pdf...
I really want to learn pawn language. |