Ranyo13
ManCausingMayhem
- Joined
- Aug 22, 2009
- Messages
- 981
- Reaction score
- 38
Hello,
I'm writing this to request help explaining a hard and large script like this one I'm going to copy and paste, please if you got the time try to explain to me every line or at least tell me how to learn to script such large scripts, and make events scripts etc. I really want to learn scripting and be good at it to contribute to the community.
Excuse my language and thanks in advance
I'm writing this to request help explaining a hard and large script like this one I'm going to copy and paste, please if you got the time try to explain to me every line or at least tell me how to learn to script such large scripts, and make events scripts etc. I really want to learn scripting and be good at it to contribute to the community.
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if(msgcontains(msg, 'prestige')) then
selfSay('Are you ready to prestige and start a new life?', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
-------CONFIGS-------
local level = 717217
local cost = 0
------/CONFIGS-------
-----LOCALS-----
local id = getPlayerGUID(cid)
local name = getCreatureName(cid)
local vocation = getPlayerVocation(cid)
local storage = getCreatureStorage(cid, 85987)
----/LOCALS-----
if(getPlayerLevel(cid) >= level) then
if(doPlayerRemoveMoney(cid, cost) == TRUE) then
if(isInArray({1, 2, 3, 4, 5, 6, 7, 8}, vocation)) then
doCreatureSetStorage(cid, 85987, storage == -1 and 1 or storage + 1)
doRemoveCreature(cid)
db.executeQuery("UPDATE `players` SET `level` = 8, `experience` = 4200, `promotion` = 0 WHERE `id` ='"..id.."';")
db.executeQuery("UPDATE `players` SET `name` = '"..name.."' WHERE `id` ='"..id.."';")
else
selfSay('Please talk with Forgotten King and promote first.', cid)
talkState[talkUser] = 0
end
else
selfSay('You don\'t have enough money. You need to pay 1 gold coin to be rebirthed.', cid)
talkState[talkUser] = 0
end
else
selfSay('Only characters of level 717217 or higher can be rebirthed.', cid)
talkState[talkUser] = 0
end
elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
selfSay('Okey. Come back when you feel ready.', cid)
talkState[talkUser] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
If you need help understanding the configs etc just ask.
4-Onlook- for yall that dont know what this is it basicly just adds this to when u look at a character
----Past the following script below in your Creaturescripts scripts folder, and save it as RebirthDescription.lua
Code:
Efunction onLook(cid, thing, position, lookDistance)
if(isPlayer(thing.uid) and thing.uid ~= cid and getCreatureStorage(thing.uid, 85987) ~= -1) then
doPlayerSetSpecialDescription(thing.uid, (getPlayerSex(thing.uid) == PLAYERSEX_FEMALE and ".\nShe" or ".\nHe") .. " has prestiged " .. getCreatureStorage(thing.uid, 85987) .. " " .. (getCreatureStorage(thing.uid, 85987) == 1 and "time" or "times"))
elseif(thing.uid == cid and getCreatureStorage(cid, 85987) ~= -1) then
local message = "You see yourself."
if(getPlayerFlagValue(cid, PLAYERFLAG_SHOWGROUPINSTEADOFVOCATION)) then
message = message .. " You are " .. getPlayerGroupName(cid) .. "."
elseif(getPlayerVocation(cid) ~= 0) then
message = message .. " You are a " .. getPlayerVocationName(cid):lower() .. "."
else
message = message .. " You have no vocation."
end
if(getPlayerNameByGUID(getPlayerPartner(cid), false, false) ~= nil) then
message = message .. " You are " .. (getPlayerSex(cid) == PLAYERSEX_FEMALE and "wife" or "husband") .. " of " .. getPlayerNameByGUID(getPlayerPartner(cid)) .. "."
end
if(getPlayerGuildId(cid) > 0) then
message = message .. " You are " .. (getPlayerGuildRank(cid) == "" and "a member" or getPlayerGuildRank(cid)) .. " of the " .. getPlayerGuildName(cid)
message = getPlayerGuildNick(cid) ~= "" and message .. " (" .. getPlayerGuildNick(cid) .. ")." or message .. "."
end
if(getPlayerFlagValue(cid, PLAYERCUSTOMFLAG_CANSEECREATUREDETAILS)) then
message = message .. "\nHealth: [" .. getCreatureHealth(cid) .. " / " .. getCreatureMaxHealth(cid) .. "], Mana: [" .. getCreatureMana(cid) .. " / " .. getCreatureMaxMana(cid) .. "]."
message = message .. "\nIP: " .. doConvertIntegerToIp(getPlayerIp(cid)) .. ", Client: " .. getClientVersion(cid) .. "."
end
if(getPlayerFlagValue(cid, PLAYERCUSTOMFLAG_CANSEEPOSITION)) then
message = message .. "\nPosition: [X: " .. position.x .. "] [Y: " .. position.y .. "] [Z: " .. position.z .. "]."
end
return false, doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, message .. " \nYou have prestiged " .. getCreatureStorage(cid, 85987) .. " " .. (getCreatureStorage(cid, 85987) == 1 and "time." or "times."))
end
return true
end
Code:
Efunction onLook(cid, thing, position, lookDistance)
if(isPlayer(thing.uid) and thing.uid ~= cid and getCreatureStorage(thing.uid, 85987) ~= -1) then
doPlayerSetSpecialDescription(thing.uid, (getPlayerSex(thing.uid) == PLAYERSEX_FEMALE and ".\nShe" or ".\nHe") .. " has prestiged " .. getCreatureStorage(thing.uid, 85987) .. " " .. (getCreatureStorage(thing.uid, 85987) == 1 and "time" or "times"))
elseif(thing.uid == cid and getCreatureStorage(cid, 85987) ~= -1) then
local message = "You see yourself."
if(getPlayerFlagValue(cid, PLAYERFLAG_SHOWGROUPINSTEADOFVOCATION)) then
message = message .. " You are " .. getPlayerGroupName(cid) .. "."
elseif(getPlayerVocation(cid) ~= 0) then
message = message .. " You are a " .. getPlayerVocationName(cid):lower() .. "."
else
message = message .. " You have no vocation."
end
if(getPlayerNameByGUID(getPlayerPartner(cid), false, false) ~= nil) then
message = message .. " You are " .. (getPlayerSex(cid) == PLAYERSEX_FEMALE and "wife" or "husband") .. " of " .. getPlayerNameByGUID(getPlayerPartner(cid)) .. "."
end
if(getPlayerGuildId(cid) > 0) then
message = message .. " You are " .. (getPlayerGuildRank(cid) == "" and "a member" or getPlayerGuildRank(cid)) .. " of the " .. getPlayerGuildName(cid)
message = getPlayerGuildNick(cid) ~= "" and message .. " (" .. getPlayerGuildNick(cid) .. ")." or message .. "."
end
if(getPlayerFlagValue(cid, PLAYERCUSTOMFLAG_CANSEECREATUREDETAILS)) then
message = message .. "\nHealth: [" .. getCreatureHealth(cid) .. " / " .. getCreatureMaxHealth(cid) .. "], Mana: [" .. getCreatureMana(cid) .. " / " .. getCreatureMaxMana(cid) .. "]."
message = message .. "\nIP: " .. doConvertIntegerToIp(getPlayerIp(cid)) .. ", Client: " .. getClientVersion(cid) .. "."
end
if(getPlayerFlagValue(cid, PLAYERCUSTOMFLAG_CANSEEPOSITION)) then
message = message .. "\nPosition: [X: " .. position.x .. "] [Y: " .. position.y .. "] [Z: " .. position.z .. "]."
end
return false, doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, message .. " \nYou have prestiged " .. getCreatureStorage(cid, 85987) .. " " .. (getCreatureStorage(cid, 85987) == 1 and "time." or "times."))
end
return true
end