24.01.2017, 20:54
(
Последний раз редактировалось iamjems; 24.01.2017 в 21:44.
)
Код:
CMD:give(playerid, params[]) { new targetid, type[10], amount, msg[144]; if(!sscanf(params, "us[10]i", targetid, type, amount)) { SendClientMessage(playerid, COLOR_GREY, "HINT: /give [playerid] [item] [amount]"); SendClientMessage(playerid, COLOR_GREY, "HINT: Items: pot"); return 1; } if(amount < 1 || amount > 9999999) return SendClientMessage(playerid, COLOR_RED, "You have typed an invalid amount."); if(targetid == playerid) return SendClientMessage(playerid, COLOR_RED, "You cannot give an item to yourself."); if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "This player was not found."); if(PlayerInfo[targetid][LoggedIn] == false) return SendClientMessage(playerid, COLOR_RED, "This player was not found."); new Float:X, Float:Y, Float:Z; GetPlayerPos(targetid, X, Y, Z); if(IsPlayerInRangeOfPoint(playerid, 5.5, X, Y, Z)) { if(!strcmp(type, "Pot", true)) { if(amount > PlayerInfo[playerid][Marijuana]) { SendClientMessage(playerid, COLOR_RED, "You don't have enough of this item on you."); return 1; } PlayerInfo[playerid][Marijuana] -= amount; PlayerInfo[targetid][Marijuana] += amount; format(msg, sizeof(msg), "You gave %s grams of marijuana to %s.", amount, GetPlayerNameEx(targetid)); SendClientMessage(playerid, COLOR_GREEN, msg); format(msg, sizeof(msg), "You received %s grams of marijuana from %s.", amount, GetPlayerNameEx(playerid)); SendClientMessage(targetid, COLOR_GREEN, msg); format(msg, sizeof(msg), "* %s hands some marijuana to %s.",GetPlayerNameEx(playerid), GetPlayerNameEx(targetid)); ProxDetector(GetPlayerVirtualWorld(playerid) == 0 ? 20.0 : 7.0, playerid, msg, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE); return 1; } } else SendClientMessage(playerid, COLOR_RED, "You are too far away from this player."); return 1; }
2. Use a cellsize of 144 for messages, as thats the maximum that can be displayed on the screen
3. Use if(!sscanf(...)) and return 1 to display the USAGE: etc.
4. I have inverted your !IsPlayerInRangeOfPoint to IsPlayerInRangeOfPoint. Added else and the message at the bottom to show the error if he is too far away from the player.
5. It's not if(!strcmp(params, "Pot", true)), it's if(!strcmp(type, "Pot", true)), because you are compaing the string "type" and "Pot"
6. Added an error if a player is not connected "if(targetid == INVALID_PLAYER_ID) return SendClientMessage(...)", keep it in mind and also always use them before arrays, i.e. PlayerInfo[targetid][LoggedIn], otherwise you will get errors like "Array index out of bounds" since the targetid is 65535 (defined as INVALID_PLAYER_ID) and the size of the array is probably MAX_PLAYERS.
7. I have made your errors a bit more simple with just "if(...) return SendClientMessage(...)"
Hope this works lad!