• 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!

An creaturescript

breadmaker

New Member
Joined
Jul 16, 2010
Messages
160
Reaction score
3
Hello,
I need one script.

Monster have storage = 3050,
If player doesn't have 3050 storage, monster cant attack him and player cant attack monster, if trying to attack:
Message cancel: "You cannot attack this monster".

If player have storage 3050, he can attack monster and monster are attacking him, after kill monster he got storage "3050,1" and he cant attack monster now :)

Anyone can do it ? :blink:
 
in creaturescript --> make 2 new lua


Lua:
local name = "rat"  -- this must be same as monster name with if monster have capitalized letter then so does this local etc..
local storage = 3050
function onCombat(cid, target)
if getPlayerStorageValue(cid, storage) < 0 and getCreatureName(target) == name then
  doPlayerSendCancel(cid,'You cannot attack this monster')
return false
if getCreatureName(cid) == name and isPlayer(target) and getPlayerStorageValue(target, storage) < 0 then
return false
end

        return true
end


Lua:
local name = "rat"   --monster name
local storage = 3050
function onKill(cid, target)
  if getCreatureName(target) == name and getPlayerStorageValue(cid,storage) > 0 then
     setPlayerStorageValue(cid,storage,-1)
   return true
end
return true
end

then in creature.xml
Code:
<event type="kill" name="die" event="script" value="xxxx.lua"/>
<event type="combat" name="dier" event="script" value="xxx.lua"/>

then in creaturescript--> login.lua
Lua:
registerCreatureEvent(cid, "die")
registerCreatureEvent(cid, "dier")

donno if this will work
 
Last edited:
daaa... , if the player have storage value -1 , then monster cant attck and he cant attack , if he have storage value 1 , then he can attck, and when he kill the monster he get storage -1 again .

i think it might work just test it
 
1679-otlandverifiesassafe.png
 
here, blind
but we didn't say it was you
Hello,
I need one script.

Monster have storage = 3050,
If player doesn't have 3050 storage, monster cant attack him and player cant attack
Message cancel: monster, if trying to attack:"You cannot attack this monster".

If player have storage 3050, he can attack monster and monster are attacking him, after kill monster he got storage "3050,1" and he cant attack monster now :)

Anyone can do it ? :blink:
 
ERRORS

PHP:
[06/08/2010 18:58:35] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/test.lua)
[06/08/2010 18:58:35] data/creaturescripts/scripts/test.lua:7: 'end' expected (to close 'if' at line 4) near 'if'
[06/08/2010 18:58:35] [Warning - Event::loadScript] Event onCombat not found (data/creaturescripts/scripts/test1.lua)

test1.lua:
PHP:
local name = "TEST SAGA"
local storage = 80950
function onCombat(cid, target)
if getPlayerStorageValue(cid, storage) < 0 and getCreatureName(target) == name then
  doPlayerSendCancel(cid,'You cannot attack this monster')
return false
if getCreatureName(cid) == name and isPlayer(target) and getPlayerStorageValue(target, storage) < 0 then
return false
end

        return true
end
test.lua:
PHP:
local name = "TEST SAGA"
local storage = 80950
function onKill(cid, target)
  if getCreatureName(target) == name and getPlayerStorageValue(cid,storage) > 0 then
     setPlayerStorageValue(cid,storage,-1)
   return true
end
return true
end
 
try mine, it's shorter and has more debug protection
Lua:
local name, storage = 'monstername', 80950

function onCombat(cid, target)
    if isPlayer(cid) and getCreatureStorage(cid, storage) < 0 and isMonster(target) and getCreatureName(target):lower() == name then
        doPlayerSendCancel(cid, 'You cannot attack this monster.')
        return false
    end    
    if isMonster(cid) and getCreatureName(cid):lower() == name and isPlayer(target) and getCreatureStorage(target, storage) < 0 then
        return false
    end
    return true
end

function onKill(cid, target, lastHit)
    if isMonster(target) and getCreatureName(target):lower() == name and isPlayer(cid) and getCreatureStorage(cid, storage) > 0 then
        doCreatureSetStorage(cid, storage, -1)
    end
    return true
end

Lua:
<event type="combat" name="dier" event="script" value="script.lua"/>
<event type="kill" name="die" event="script" value="script.lua"/>
 
Another error

The mob(monster) not attacking me just following me (no deal damage) and i can attack him... <- I dont have required storage, of course
 
Last edited:
Back
Top