Guest User

Party System

a guest
Oct 26th, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.33 KB | None | 0 0
  1. function onSay(cid, words, param)
  2. t = string.explode(param, ",")
  3. stor = 31721
  4. pname = 31722
  5. max = 3 -- Mรกximo de players na party
  6.  
  7.     if t[1] == "invite" then
  8.         if not t[2] then
  9.             doPlayerSendCancel(cid, "Incorrect params.") return true
  10.         elseif not isInParty(cid) or getPartyLeader(cid) ~= cid then
  11.             doPlayerSendCancel(cid, "You must be a party leader to use this command.") return true
  12.         elseif not getPlayerByName(t[2]) then
  13.             doPlayerSendCancel(cid, "Player not found.") return true
  14.         elseif #getPartyMembers(cid) >= max then
  15.             doPlayerSendCancel(cid, "Sorry, but your party is at the full capacity ("..max.." players).") return true
  16.         elseif isInParty(getPlayerByName(t[2])) then
  17.             doPlayerSendCancel(cid, "Sorry, but this player is already in a party.") return true
  18.         elseif getPlayerStorageValue(getPlayerByName(t[2]), pname) ~= -1 then
  19.             doPlayerSendCancel(cid, "Sorry, but this player already has an invitation.") return true
  20.         end
  21.        
  22.         doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You invited "..t[2].." to your party.")
  23.         doPlayerSendTextMessage(getPlayerByName(t[2]), MESSAGE_STATUS_CONSOLE_BLUE, "You have been invited to a party by "..getCreatureName(cid)..". Use !party accept or reject.")
  24.         setPlayerStorageValue(getPlayerByName(t[2]), stor, 1)
  25.         setPlayerStorageValue(getPlayerByName(t[2]), pname, getCreatureName(cid))
  26.     elseif t[1] == "accept" then
  27.         if t[2] then
  28.             doPlayerSendCancel(cid, "Incorrect params.") return true
  29.         elseif not getPlayerStorageValue(cid, stor) == 1 then
  30.             doPlayerSendCancel(cid, "You haven't any party invitations.") return true
  31.         elseif isInParty(cid) then
  32.             doPlayerSendCancel(cid, "You are already in a party.") return true
  33.         elseif not getPlayerByName(getPlayerStorageValue(cid, pname)) then
  34.             doPlayerSendCancel(cid, "The party leader is offline. Invitation canceled.")
  35.             setPlayerStorageValue(cid, stor, -1)
  36.             setPlayerStorageValue(cid, pname, -1) return true
  37.         end
  38.        
  39.         setPlayerStorageValue(cid, stor, -1)
  40.         doPlayerSendTextMessage(getPlayerByName(getPlayerStorageValue(cid, pname)), MESSAGE_STATUS_CONSOLE_BLUE, ""..getCreatureName(cid).." has joined your party.")
  41.         doPlayerJoinParty(cid, getPlayerByName(getPlayerStorageValue(cid, pname)))
  42.         setPlayerStorageValue(cid, pname, -1)
  43.     elseif t[1] == "reject" then
  44.         if t[2] then
  45.             doPlayerSendCancel(cid, "Incorrect params.") return true
  46.         elseif not getPlayerStorageValue(cid, stor) == 1 then
  47.             doPlayerSendCancel(cid, "You haven't any party invitations.") return true
  48.         elseif isInParty(cid) then
  49.             doPlayerSendCancel(cid, "You are already in a party.") return true
  50.         elseif not getPlayerByName(getPlayerStorageValue(cid, pname)) then
  51.             doPlayerSendCancel(cid, "The party leader is offline. Invitation canceled.")
  52.             setPlayerStorageValue(cid, stor, -1)
  53.             setPlayerStorageValue(cid, pname, -1) return true
  54.         end
  55.        
  56.             doPlayerSendTextMessage(getPlayerByName(getPlayerStorageValue(cid, pname)), MESSAGE_STATUS_CONSOLE_BLUE, ""..getCreatureName(cid).." has rejected your party invitation.")
  57.             setPlayerStorageValue(cid, stor, -1)
  58.             setPlayerStorageValue(cid, pname, -1)
  59.     elseif t[1] ~= "invite" or t[1] ~= "accept" or t[1] ~= "reject" then
  60.         return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'You can only "invite" a player to your party or "accept" or "reject" an invitation.')
  61.     end
  62. return true
  63. end
Advertisement
Add Comment
Please, Sign In to add comment