• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

few things im stuggling with

fishie

fishies-war
Joined
Oct 27, 2016
Messages
78
Reaction score
2
Recently ive started working on a new project and im struggling with a few things.

#1 Id like to make it so that when a player dies the level resets back to basic but everything else stays the same (equipment, addons, skills etc)

#2 When a player gets a pvp kill id like to make it so it adds a kill to the player then the player and people can look at the player and see his kills

#3 With a players kills would it be possible to use them to accsess level doors? e.g player needs 100 kills to use the door

thankyou for your help, if i need to explain further whats needed please ask :)

fish
 
#1: creaturescript onPrepareDeath
Code:
function onPrepareDeath(cid, lastHitKiller, mostDamageKiller)
    db.query("UPDATE `players` SET `level` = 8, `experience` = 4200")
    return true
end


#2: creaturescript onKill
Code:
function onKill(cid, target, damage, flags)
    if isPlayer(target.uid) then
        local storage = getPlayerStorageValue(cid, 80000)
        doPlayerSetStorageValue(cid, 80000, storage == -1 and 0 or storage + 1)
    end
    return true
end

#2 (part 2): creaturescript onLook
Code:
function onLook(cid, thing, position, lookDistance)
    local pmessage = ""
    if(isPlayer(thing.uid) and thing.uid ~= cid and getPlayerStorageValue(thing.uid, 80000) ~= -1) then
        if(getPlayerStorageValue(thing.uid, 80000) > -1) then
            doPlayerSetSpecialDescription(thing.uid, (getPlayerSex(thing.uid) == PLAYERSEX_FEMALE and ".\nShe" or ".\nHe") .. " has [" .. getPlayerStorageValue(thing.uid, 80000) .. "] " .. (getPlayerStorageValue(thing.uid, 80000) == 1 and "Kill" or "Kills"))
        end
    elseif(thing.uid == cid and getPlayerStorageValue(cid, 80000) ~= -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(getPlayerByName(getPlayerPartner(cid), false, false) ~= nil) then
            message = message .. " You are " .. (getPlayerSex(cid) == PLAYERSEX_FEMALE and "wife" or "husband") .. " of " .. getPlayerByName(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)) .. "."
        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 [" .. getPlayerStorageValue(cid, 80000) .. "] " .. (getPlayerStorageValue(cid, 80000) == 1 and "Kill" or "Kills"))
    end
    return true 
end



#3: actions onUse
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerStorageValue(cid, 80000) >= 100 then
        return true
    else
        return false
    end
end
 
Don't bump before 24h after last post!
Sorry for being a total noob but how would I implement all of this to the server then?

Anyone? I added it how i thought but it hasnt worked.

@Xeraphus?
 
Last edited:
Hi there, Can you please tell me what distro you are using?

All the scripts except the last one that Xeraphus made for you are supposed to be in the creaturescripts > scripts folder. Then you need to register them in creaturescripts.xml that can be found in the creaturescripts folder.

You can take a look on the other scripts that are already registered to see how you need to register them.

The last script belongs in the
actions folder.
 
Im using TFS 1.2 ive added all the scripts to the creaturescripts > scripts

Added them to the creaturescripts.xml but not sure i done it correct. How should it look?

<event type="preparedeath" name="preparedeath" script="onPrepareDeath.lua" />
<event type="kill" name="onkill" script="onKill.lua" />
<event type="login" name="onlook" script="onLook.lua" />
 
you also have to register them in your login.lua
near the bottom you should see
Code:
player:registerEvent('eventname')
do this but for all the script names (the names you put in xml)
 
So my creature scripts should look like

<event type="preparedeath" name="preparedeath" script="onPrepareDeath.lua" />
<event type="kill" name="onkill" script="onKill.lua" />
<event type="login" name="onlook" script="onLook.lua" />

then my login.lua should look like

-- Events
player:registerEvent("PlayerDeath")
player:registerEvent("DropLoot")
player:registerEvent("OnKill")
player:registerEvent("PrepareDeath")
player:registerEvent("OnLogin")
return true
end

It still dosnt work ;/
 
So my creature scripts should look like

<event type="preparedeath" name="preparedeath" script="onPrepareDeath.lua" />
<event type="kill" name="onkill" script="onKill.lua" />
<event type="login" name="onlook" script="onLook.lua" />

then my login.lua should look like

-- Events
player:registerEvent("PlayerDeath")
player:registerEvent("DropLoot")
player:registerEvent("OnKill")
player:registerEvent("PrepareDeath")
player:registerEvent("OnLogin")
return true
end

It still dosnt work ;/
you aren't registering the event name with that, you're trying to register the script type
it's case sensitive
also you shouldn't name them like that (an onLook event named onlook) because it's confusing

say you have this:
<event type="login" name="storagelook" script="onLook.lua" />
you would register it with:
player:registerEvent("storagelook")
 
So what is written in my creature scripts is correct?

<event type="preparedeath" name="preparedeath" script="onPrepareDeath.lua" />
<event type="kill" name="onkill" script="onKill.lua" />
<event type="login" name="onlook" script="onLook.lua" />

just need to change my login? ill try it later and post results
 
So what is written in my creature scripts is correct?

<event type="preparedeath" name="preparedeath" script="onPrepareDeath.lua" />
<event type="kill" name="onkill" script="onKill.lua" />
<event type="login" name="onlook" script="onLook.lua" />

just need to change my login? ill try it later and post results
technically yes but you shouldn't name your events like that because it's confusing to know what it is
 
All is now as u have said but it dosnt work,

my creature scripts =

<event type="preparedeath" name="preparedeath" script="onPrepareDeath.lua" />
<event type="kill" name="kill" script="onKill.lua" />
<event type="kill" name="Ghaz" event="script" value="script.lua"/>

and my login looks like

player:registerEvent("kill")
player:registerEvent("preparedeath")
player:registerEvent("look")


yet it still dosnt work. What am i doing wrong?
 
you never said what tfs you were using so i made code for older versions
ill post newer code for 1.2 later
 
Code:
function onDeath(player, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    player:removeExperience(player:getExperience() - (player:getExperience() - 4200))
    return true
end

Code:
function onKill(creature, target)
    if creature:getPlayer() and target:getPlayer() then
        local storage = player:getStorageValue(80000)
        player:setStorageValue(storage == -1 and 0 or storage + 1)
    end
    return true
end

Code:
local value = 100 -- how many kills needed to pass

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not (player:getStorageValue(80000) >= value) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, 'You must have '.. value ..'+ kills to go through this door')
        return false
    end
    return true
end

events/scripts/player.lua in function Player:eek:nLook
find self:sendTextMessage(MESSAGE_INFO_DESCR, description) at the end
add this before it
Code:
local isSelf, kills = thing == self, player:getStorageValue(80000)
    description = description .. string.format('\n%s %s %d %s', isSelf and 'you' or thing:getSex() == PLAYERSEX_MALE and 'he' or 'she', isSelf and 'have' or 'has', kills, kills == 1 and 'kill' or 'kills')
 
Added it all but now when u try look at anything nothing apears ;/

removed,
local isSelf, kills = thing == self, player:getStorageValue(80000)
description = description .. string.format('\n%s %s %d %s', isSelf and 'you' or thing:getSex() == PLAYERSEX_MALE and 'he' or 'she', isSelf and 'have' or 'has', kills, kills == 1 and 'kill' or 'kills')

and everything works as should but not the kills
 
Added it all but now when u try look at anything nothing apears ;/

removed,
local isSelf, kills = thing == self, player:getStorageValue(80000)
description = description .. string.format('\n%s %s %d %s', isSelf and 'you' or thing:getSex() == PLAYERSEX_MALE and 'he' or 'she', isSelf and 'have' or 'has', kills, kills == 1 and 'kill' or 'kills')

and everything works as should but not the kills
change player:setStorageValue to creature:setStorageValue in the kill function
change thing == self to thing.uid == self.uid
 
Back
Top