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

Lua Checking whether a player is targetting something.

Siegh

Thronar Developer
Joined
Mar 12, 2011
Messages
1,186
Solutions
1
Reaction score
510
Location
Brazil
Hello, I need help on some quick subject, I haven't been able to find this exact issue on other threads so far.

I simply needs to change variables when casting a spell, and the desired condition is whether the caster is or not targetting a creature.

Here is what I'm working with so far (didn't give it much thought, it should return a false value if nothing is found, but it isn't).

Code:
if getCreatureTarget(cid) == false then
    combat = level1S
else
    combat = level1A
end

I will really appreciate the help!
 
Solution
Function getCreatureTarget() will return 0 if there is no target. In Lua only false and nil is considered as false by logical operators. That's why it always returns level1A.
Try:
Lua:
if getCreatureTarget(cid) ~= 0 then
    combat = level1A
else
    combat = level1S
end
getCreatureTarget returns a creature id, not a bool
if getCreatureTarget(cid) then

or

if not getCreatureTarget(cid) then
 
getCreatureTarget returns a creature id, not a bool
if getCreatureTarget(cid) then

or

if not getCreatureTarget(cid) then
Thanks for the quick reply!
It's still not working properly, have I done something wrong? It's always returning level1A.

Code:
    if getCreatureTarget(cid) then
        combat = level1A
    elseif not getCreatureTarget(cid) then
        combat = level1S
    end
 
Function getCreatureTarget() will return 0 if there is no target. In Lua only false and nil is considered as false by logical operators. That's why it always returns level1A.
Try:
Lua:
if getCreatureTarget(cid) ~= 0 then
    combat = level1A
else
    combat = level1S
end
 
Solution
Function getCreatureTarget() will return 0 if there is no target. In Lua only false and nil is considered as false by logical operators. That's why it always returns level1A.
Try:
Lua:
if getCreatureTarget(cid) ~= 0 then
    combat = level1A
else
    combat = level1S
end

That did work perfectly, thanks for the assistance!
 
Back
Top Bottom