Action Snake system

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Best answers
0
Reaction score
100
Location
Brazil
Hello, Cybershot asked to me create an snake system so i done it


Ir worked 100% on TFS 0.3.6

First create something like this

Set one center and 6 sqm to < 6 to > 4 to /\ and 4 to \/
Next:

Dont need any aid.
And to enter:

Add this tag on actions.xml:
Code:
<action itemid="9564" event="script" value="snakesys.lua"/>
on Data/actions/scripts create snakesys.lua
ad add this:
Code:
function onUse(cid, item, frompos, item2, topos)
    if not isPlayer(getGlobalStorageValue(SNAKE.freeglobalstorage)) then
        doTeleportThing(cid,SNAKE.controlpos)
        SNAKE.timer(cid,1,nil,item.actionid == 0 and 500 or item.actionid)
        doPlayerSendTextMessage(cid,25,'Hold key CTRL and use the arrows to control snake.')
        SNAKE.generateFood()
    else
        doPlayerSendTextMessage(cid,25,'Please wait.')
    end
end
Now if you use TFS 0.3.4 or less you need add dofile('data/lib/snakesys.lua') on functions.lua
If you use 0.3.6 or 0.3.5 only add snakesys.lua on data/lib
and set it on snakesys.lua

Code:
--[[
Script by Mock the bear
]]
SNAKE = {
    _VERSION="1.0 by mock",
    ---Snake config
    itemid=1739,
    freeglobalstorage=28103,
    itemFood=6394,
    controlpos={x=1013,y=1164,z=6},
    exitpos = {x=1009,y=1157,z=7},
    centerpos={x=1012,y=1163,z=7},
    timer = function(cid,n,pos_,time)
        local pos_ = pos_ or {{SNAKE.centerpos}}
        setGlobalStorageValue(SNAKE.freeglobalstorage,cid)
        if not isPlayer(cid) then
            SNAKE.clean()
            return
        end
            for i,pos in pairs(pos_) do
                SNAKE.find_and_delete(pos[1])
                if i == 1 then
                    pos[2] = SNAKE.copypos(pos[1])
                    pos[1] = getPosByDir({x=pos[1].x,y=pos[1].y,z=pos[1].z,stackpos=255},getCreatureLookDir(cid))
                else
                    pos[2] = SNAKE.copypos(pos[1])
                    pos[1] = pos_[i-1][2]
                end
                local ret,p,walk = SNAKE.check(pos[1])
                if ret == 1 or ret == 3 then
                    addEvent(doTeleportThing,1000,cid,SNAKE.exitpos)
                    addEvent(doCreatureSay,1100,cid,'Points '..(#pos_-1)..'.')
                    SNAKE.clean()
                    setGlobalStorageValue(SNAKE.freeglobalstorage,0)
                    return
                end
                if ret == 2 then
                    doRemoveItem(p.uid,-1)
                    if p.itemid == SNAKE.itemFood then
                        pos_[#pos_+1] = {pos[2],pos[2]}
                        for i=1,5 do
                            addEvent(doSendMagicEffect,100*i,pos[1],29)
                        end
                        SNAKE.generateFood()
                    end
                end
                doCreateItem(SNAKE.itemid,1,pos[1])

            end
            local plpos = getCreaturePosition(cid)
            local generated = {}
            for i=0,3 do
                generated = getPosByDir({x=SNAKE.controlpos.x,y=SNAKE.controlpos.y,z=SNAKE.controlpos.z},i)
            end
            for i,pos in pairs(generated) do
                if SNAKE.samepos(plpos,pos) then

                    doTeleportThing(cid,SNAKE.controlpos,false)
                end
                addEvent(doSendMagicEffect,100,pos,56,cid)
            end
        addEvent(SNAKE.timer,time,cid,n,pos_,time)
    end,
    copypos = function(p)
        return {x=p.x,y=p.y,z=p.z,stackpos=p.stackpos}
    end,
    samepos = function(p1,p2)
        if p1.x == p2.x and p2.y == p2.y then
            return true
        end
        return false
    end,
    generateFood = function()
        local pp = {x=SNAKE.centerpos.x+math.random(-6,6),y=SNAKE.centerpos.y+math.random(-4,4),z=SNAKE.centerpos.z}
        for i=1,5 do
            addEvent(doSendMagicEffect,100*i,pp,30)
        end
        doCreateItem(SNAKE.itemFood,1,pp)
    end,
    clean = function()
        for y=-4,4 do
            for x=-6,6 do
                local pp = {x=SNAKE.centerpos.x+x,y=SNAKE.centerpos.y+y,z=SNAKE.centerpos.z}
                for i=250,255 do
                    pp.stackpos = i
                    local p = getThingFromPos(pp)
                    if p.itemid ~= 0 then
                        doRemoveItem(p.uid,-1)
                        doSendMagicEffect(pp,15)
                    end
                end
            end
        end
    end,
    check = function(pos)
        for i=1,10 do
            pos.stackpos = i
            local p = getThingFromPos(pos)
            if p.itemid == SNAKE.itemid then
                return 1,p,true
            elseif not SNAKE.isWalkable(pos) then
                return 3,p,false
            elseif p.itemid ~= 0 then
                return 2,p
            end
        end
        return false
    end,
    find_and_delete = function(pos)
        for i=0,255 do
            pos.stackpos = 255-i
            local p = getThingFromPos(pos)
            if p.itemid == SNAKE.itemid then
                return doRemoveItem(p.uid,1)
            end
        end
    end,
    isWalkable = function(pos, creature, proj, pz)-- by Nord
        if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
        if getTopCreature(pos).uid > 0 and creature then return false end
        if getTileInfo(pos).protection and pz then return false, true end
        local n = not proj and 3 or 2
        for i = 0, 255 do
            pos.stackpos = i
            local tile = getTileThingByPos(pos)
            if tile.itemid ~= 0 and not isCreature(tile.uid) then
                if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
                    return false
                end
            end
        end
        return true
    end,
}

Done

If you want seed Snake in action and how to install check on this video:
YouTube - Snake system by mock - demonstration / instalation

Like? Rep++ ;D (or not :()

PS: You have to teleport the character UPSTAIRS! one floor above the game!
 
Last edited by a moderator:

cbrm

Top Class brunet scripter
Staff member
Global Moderator
Joined
Jan 6, 2009
Messages
6,584
Best answers
3
Reaction score
850
Location
Caribbean Sea
tank you man, i'll test it asap =p
God bless your superlua powers :p
 

Rexanilator

Member
Joined
Oct 3, 2009
Messages
297
Best answers
0
Reaction score
2
wow cool script ill try it out in a few!

I would rep you but I always got to spread rep around before I can rep you again :(
 
Last edited:

iBlue

Banned User
Joined
Feb 23, 2010
Messages
1,557
Best answers
0
Reaction score
33
Location
Missouri
LMAO that shiz is noice!!! Fking Mock owning the script gameeeeeeeeeeeeeeeeeeeeee
 

zakius

Enter the Ninja!
Joined
Apr 30, 2009
Messages
2,635
Best answers
0
Reaction score
61
Location
with Taiga
you're insane Mock, but you know, you're my favourite bear xD
but still I'm thinking how to control mario, aff, jumping while running would be hard...

EDIT: hah, I just had idea: what about multiplayer pong?
 
Last edited:

Jano

oturhaN
Joined
Feb 21, 2008
Messages
874
Best answers
0
Reaction score
65
Location
Chile
nice one, snake its my fav old game :x
 

Blackish

Member
Joined
Jun 3, 2009
Messages
230
Best answers
0
Reaction score
0
Location
Earth
Dude good job btw could you post the mapp?
know its really easy to mapp it but i dont have time:S
 

Colandus

Legendary OT User
Joined
Jun 6, 2007
Messages
2,424
Best answers
18
Reaction score
165
Location
Sweden
cool.... imma make my own version of it later :D

Suggestions:
- configurable snake can go through wall
- instead of movable items, transform ground tiles.....

Cool. It was even better than I thought, there are snake-tiles ready!


If you don't make it, I will... But not quite yet ;) But it would be nice if you spare me the time :D
 

Henkos

Active Member
Joined
Jun 29, 2008
Messages
2,989
Best answers
0
Reaction score
3
Awesome!

But what happens if you "Drive" the snake on yourself?

Also the first box should be changed into something else as it is easy to think someone else is first when the snake gets long.
 

cbrm

Top Class brunet scripter
Staff member
Global Moderator
Joined
Jan 6, 2009
Messages
6,584
Best answers
3
Reaction score
850
Location
Caribbean Sea
Awesome!

But what happens if you "Drive" the snake on yourself?

Also the first box should be changed into something else as it is easy to think someone else is first when the snake gets long.
nothing, the snakebox keeps running
:p i only like to play in hard mode
a better idea to hide the player:

set player's outfit like a stone tile
hide player's health with doCreatureSetHideHealth(cid, hide)

then it'll look alike as if only the snake was playing ;D
 
Last edited:

zakius

Enter the Ninja!
Joined
Apr 30, 2009
Messages
2,635
Best answers
0
Reaction score
61
Location
with Taiga
@up galaga, galaxian, space invaders, whatever xD
but it would need bigger screen probably, just like asteroid(s?)

I'll say: pong, maybe arkanoid
 

Rexanilator

Member
Joined
Oct 3, 2009
Messages
297
Best answers
0
Reaction score
2
You go a floor above that floor to floor 6 and you put void id 460 You can find void in raw pallete grounds
 
Top