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

Action Football field (scripts + maps)

Gesior.pl

Mega Noob&LOL 2012
Senator
Joined
Sep 18, 2007
Messages
2,955
Solutions
98
Reaction score
3,351
Location
Poland
GitHub
gesior
(use Actions, Movements, Globalevents, tested on TFS 0.3.4pl2)
Informations:
- movie (speed x2):
YouTube - football
- 3 football field maps [ 2 maps for 2 vs 2, 1 for 3 v 3 matches] (xxx aids, ~40 uids :p )
- same speed (configurable) for all players (utani hur/gran hur, time ring, boots of speed dont work, level doesnt change speed)
- auto move ball and teleport players (teleport players configurable) to start positions after goal
- auto remove items (other then football) from football field
- auto kick players from football field after X minutes (configurable)
- broadcast score
20:40 Football field 2. Team 1 (Gesior 2, Gesior) - 2 : 1 - (test 2, test 1) Team 2
- send player messages
20:40 Match start. You are in Team 2 on field 2. You have 0.5 minutes.
...
20:40 You were in Team 2 on field 2 (you can use few football fields in same time). Team 1 (Gesior 2, Gesior) - 2 : 1 - (test 2, test 1) Team 2
- auto change outfit colors of team members (all members have color as first player from their team [near switch])
SCRIPT
1. Map link (copy 1 - 3 football fields to your map, dont modify UID/AIDs)
http://uploadhyper.com/file/10456/football.otbm.html
2. in data/lib/data.lua at end of file paste:
PHP:
dofile(getDataDir() .. "lib/football.lua")
3. in data/lib/ create file football.lua and paste:
PHP:
-- 1 - exit pos , 2 - team 1 ball, 3 - team 2 ball, 4 - team1frompos, 5 -team2frompos, 6 - team1topos, 7 - team2topos, 8-team1gate aid, 9 - team2game aid, 10 - speed, 11 - match time, 12 - highest uid + 1, 13 - field size
football_positions_uids = {}
football_positions_uids[1] = {23301,23302,23303, {23304,23305,23306}, {23307,23308,23309}, {23310,23311,23312}, {23313,23314,23315}, 23311, 23312, 450, 3, 23315, {8,3}}
football_positions_uids[2] = {23320,23321,23322, {23323,23324}, {23325,23326}, {23327,23328}, {23329,23330}, 23321, 23322, 450, 3, 23330, {6,2}}
football_positions_uids[3] = {23340,23341,23342, {23343,23344}, {23345,23346}, {23347,23348}, {23349,23350}, 23341, 23342, 450, 3, 23350, {6,2}}
teleport_players_on_goal = true


function footballGoal(pos, ball, team1pos, team2pos, goalStorage, ballpos) -- add goal to team 1/2 score, show "GOAL", animations, teleport ball and players
	setGlobalStorageValue(goalStorage, getGlobalStorageValue(goalStorage)+1)
	if(teleport_players_on_goal) then
		for i = 1 , #team1pos do
			doTeleportThing(getGlobalStorageValue(team1pos[i]), getThingPos(team1pos[i]), TRUE)
		end
		for i = 1 , #team2pos do
			doTeleportThing(getGlobalStorageValue(team2pos[i]), getThingPos(team2pos[i]), TRUE)
		end
	end
	doSendMagicEffect(pos, CONST_ME_BATS)
	doTeleportThing(ball.uid, ballpos, TRUE)
	doSendMagicEffect(ballpos, CONST_ME_MAGIC_GREEN)
	doSendAnimatedText(ballpos, "GOAL!", TEXTCOLOR_TEAL)
end

function footballGetBall(startFromPos, fieldSize) -- get ball uid or create new and return uid, remove all balls from football field (if any exist)
	ball = 0
	for ix = startFromPos.x - fieldSize[1], startFromPos.x + fieldSize[1] do
		for iy = startFromPos.y - fieldSize[2], startFromPos.y + fieldSize[2] do
			tmpBall = getTileItemById({x=ix, y=iy, z=startFromPos.z}, 2109)
			if(tmpBall.uid > 0) then
				if(ball == 0) then
					ball = tmpBall.uid
				else
					doRemoveItem(tmpBall.uid)
				end
			end
		end
	end
	if(ball == 0) then
		return doCreateItem(2109, 1, startFromPos)
	else
		return ball
	end
end
4. in data\actions\scripts\ create file football.lua and paste:
PHP:
function onUse(cid, item, frompos, item2, topos)
	if(item.itemid == 1945 or item.itemid == 1946) then
		match = football_positions_uids[item.actionid-23300]
		if(getGlobalStorageValue(match[1]) < 1) then
			fromPoss = {match[4], match[5]}
			toPoss = {match[6], match[7]}
			players_number = 0
			for i = 1, 2 do
				teamPoss = fromPoss[i]
				for p = 1, #teamPoss do
					if(isPlayer(getTopCreature(getThingPos(teamPoss[p])).uid) == TRUE) then
						players_number = players_number + 1
					end
				end
			end
			if(players_number ~= #fromPoss[1] + #fromPoss[2]) then
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, #fromPoss[1] + #fromPoss[2] .. " players needed. Only " .. players_number .. " on start positions.")
				return false
			end
			setGlobalStorageValue(match[1], os.time() + match[11] * 60)
			ballPos = getThingPos(match[2])
			doTeleportThing(footballGetBall(getThingPos(match[2]), match[13]), ballPos, TRUE)
			addEvent(doSendAnimatedText, 4000, ballPos, "0!", TEXTCOLOR_TEAL)
			addEvent(doSendAnimatedText, 3000, ballPos, "1", TEXTCOLOR_TEAL)
			addEvent(doSendAnimatedText, 2000, ballPos, "2", TEXTCOLOR_TEAL)
			addEvent(doSendAnimatedText, 1000, ballPos, "3", TEXTCOLOR_TEAL)
			teamOutfit = {}
			for i = 1, 2 do
				teamFromPoss = fromPoss[i]
				teamToPoss = toPoss[i]
				teamOutfit[i] = getCreatureOutfit(getTopCreature(getThingPos(teamFromPoss[1])).uid)
				for p = 1, #teamFromPoss do
					player = getTopCreature(getThingPos(teamFromPoss[p])).uid
					setGlobalStorageValue(teamToPoss[p], player)
					doCreatureSetNoMove(player, 1)
					addEvent(doCreatureSetNoMove, 4000, player, 0)
					outfit = getCreatureOutfit(player)
					outfit.lookHead = teamOutfit[i].lookHead
					outfit.lookBody = teamOutfit[i].lookBody
					outfit.lookLegs = teamOutfit[i].lookLegs
					outfit.lookFeet = teamOutfit[i].lookFeet
					doSetCreatureOutfit(player, outfit, match[11] * 60 * 1000 + 2500)
					doTeleportThing(player, getThingPos(teamToPoss[p]), TRUE)
					doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_ORANGE, "Match start. You are in Team " .. i .. " on field " .. item.actionid-23300 .. ". You have " .. match[11] .. " minutes.")
				end
			end
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Football field in use. Please wait.")
			return false
		end
		return true
	end
	return false
end
5. in data\actions\actions.xml add:
PHP:
<action fromaid="23301" toaid="23304" event="script" value="football.lua"/>
6. in data\movements\scripts\ create file football.lua and paste:
PHP:
function onAddItem(moveitem, tileitem, pos)
	if(moveitem.itemid ~= 2109 and tileitem.actionid <= 23310) then -- remove trash
		match = football_positions_uids[tileitem.actionid-23300]
		exitPos = getThingPos(match[1])
		doSendMagicEffect(exitPos, CONST_ME_BATS)
		doTeleportThing(moveitem.uid, exitPos, TRUE)
	else -- goal or trash (ignore) in gate
		if(moveitem.itemid == 2109 and tileitem.actionid > 23310) then
			for i = 1, #football_positions_uids do
				match = football_positions_uids[i]
				if(match[8] == tileitem.actionid) then
					footballGoal(pos, moveitem, match[6], match[7], match[3], getThingPos(match[2]))
					break
				elseif(match[9] == tileitem.actionid) then
					footballGoal(pos, moveitem, match[6], match[7], match[2], getThingPos(match[3]))
					break
				end
			end
		end
	end
	return TRUE
end

function onStepIn(cid, item, position, fromPosition)
	if(item.actionid <= 23304) then
		match = football_positions_uids[item.actionid-23300]
		if(getCreatureSpeed(cid) ~= match[10]) then
			doRemoveCondition(cid, CONDITION_HASTE)
			doChangeSpeed(cid, match[10] - getCreatureSpeed(cid))
		end
	end
	return TRUE
end
7. in data\movements\movements.xml add:
PHP:
<movevent type="AddItem" tileitem="1" fromaid="23300" toaid="23400" event="script" value="football.lua"/>
	<movevent type="StepIn" fromaid="23300" toaid="23400" event="script" value="football.lua"/>
8. in data\globalevents\scripts\ create file football.lua and paste:
PHP:
function onThink(interval, lastExecution)
	for m = 1 , #football_positions_uids do
		match = football_positions_uids[m]
		if(getGlobalStorageValue(match[1]) == -1) then
			for t = match[1], match[12] do
				setGlobalStorageValue(t, 0)
			end
		end
		end_time = getGlobalStorageValue(match[1])
		if(end_time > 0 and end_time < os.time()) then
			toPoss = {match[6], match[7]}
			team_players = {"", ""}
			for i = 1, 2 do
				teamPoss = toPoss[i]
				for p = 1, #teamPoss do
					team_players[i] = team_players[i] .. getCreatureName(getGlobalStorageValue(teamPoss[p]))
					if p ~= #teamPoss then
						team_players[i] = team_players[i] .. ", "
					end
				end
			end
			score = "Team 1 (" .. team_players[1] .. ") - " .. getGlobalStorageValue(match[2]) .. " : " .. getGlobalStorageValue(match[3]) .. " - (" .. team_players[2] .. ") Team 2"
			doBroadcastMessage("Football field " .. m .. ". " .. score, MESSAGE_STATUS_CONSOLE_BLUE)
			for i = 1, 2 do
				teamPoss = toPoss[i]
				exitPos = getThingPos(match[1])
				for p = 1, #teamPoss do
					doTeleportThing(getGlobalStorageValue(teamPoss[p]), exitPos, TRUE)
					doPlayerSendTextMessage(getGlobalStorageValue(teamPoss[p]), MESSAGE_STATUS_CONSOLE_ORANGE, "You were in Team " .. i .. " on field " .. m .. ". " .. score)
				end
			end
			for i = match[1], match[12] do
				setGlobalStorageValue(i, 0)
			end
		end
	end
	return true
end
9. in data\globalevents\globalevents.xml add:
PHP:
<globalevent name="football" interval="5" event="script" value="football.lua"/>
 

Attachments

Last edited by a moderator:
Is the ball configured to only move 1 tile at a time? if not people could cheat too much even if its an accident :/
 
Are you boored`?

If your asking me..no.
I have a soccer field on my server and when someone throws the ball 6 sqm its no fun lol..if u made this an actual event you would want it to be strict. Anything else?
 
If your asking me..no.
I have a soccer field on my server and when someone throws the ball 6 sqm its no fun lol..if u made this an actual event you would want it to be strict. Anything else?
Hmm.. TFS/tibia client block ball move range to 2 :>
Are you boored`?
I make new rpg ots and need many scripts.
 
Hah, i've made similar soccer system 6 months ago :p, anyway GJ :)

(My is using less storages, uniques :p)
 
I used to have one also, for 8.0, long time ago.
Good work.
 
When i have finish the football..
i dont get tp out from there i get this error in console
Code:
[12/09/2009 04:06:07] Lua Script Error: [GlobalEvent Interface] 
[12/09/2009 04:06:07] data/globalevents/scripts/football.lua:onThink

[12/09/2009 04:06:07] luaGetThingPos(). Thing not found

[12/09/2009 04:06:28] Lua Script Error: [MoveEvents Interface] 
[12/09/2009 04:06:28] data/movements/scripts/football.lua:onAddItem

[12/09/2009 04:06:28] luaDoTeleportThing(). Thing not found
bump
 
Last edited:
When i have finish the football..
i dont get tp out from there i get this error in console
Code:
[12/09/2009 04:06:07] Lua Script Error: [GlobalEvent Interface] 
[12/09/2009 04:06:07] data/globalevents/scripts/football.lua:onThink

[12/09/2009 04:06:07] luaGetThingPos(). Thing not found

[12/09/2009 04:06:28] Lua Script Error: [MoveEvents Interface] 
[12/09/2009 04:06:28] data/movements/scripts/football.lua:onAddItem

[12/09/2009 04:06:28] luaDoTeleportThing(). Thing not found
bump
Bump
 
That's why Gesior's scripts sux, many uniques, actions, storages. Then peoples can't get it work =S
 
when i have finish the football..
I dont get tp out from there i get this error in console
Code:
[12/09/2009 04:06:07] lua script error: [globalevent interface] 
[12/09/2009 04:06:07] data/globalevents/scripts/football.lua:onthink

[12/09/2009 04:06:07] luagetthingpos(). Thing not found

[12/09/2009 04:06:28] lua script error: [moveevents interface] 
[12/09/2009 04:06:28] data/movements/scripts/football.lua:onadditem

[12/09/2009 04:06:28] luadoteleportthing(). Thing not found
bump

bump
 
That's why Gesior's scripts sux, many uniques, actions, storages. Then peoples can't get it work =S
MAAANY actions/uniques are FOR USERS (they can copy map and scripts), of course I could make script with 233748 positions in config file, but it's waste of time.
(in every my script I use new uids/aids)
With my simple script you copy it to your map and it work (tfs 0.3.4pl2).
I know many other scripts from forum without uids/aids, but little change/bug in map/scripts config let players copy items, make mlvl or any other abuse. I hate scripts that let players abuse bug.
@Chipsen
is it when you play first match on football field? or did you teleport anyone from football field (players on field can't logout [no logout tile])?
do you have in config.lua:
saveGlobalStorage = "yes"
?
@Donio
I didn't see any football script in last 1/2 year. I made it from zero for my otses.
 
Last edited:
Gesior, I still love your script ideas, and because of this I'll rep you :thumbup:.

EDIT:
You must spread some Reputation around before giving it to Gesior.pl again.
 
Maybe I'm not pro scripter (I don't know advanced language options like Talaturen, Remere, Simone, Wrzasq and rest of server distro developers), but I have good (easy to add for newbies) ideas for scripts :)
@Chojrak
check:
http://otland.net/f81/advanced-quest-chest-14929/
and what TFS developers (Elf added this script) added as 'easy quest script' (my script wasn't sooo optimized, but work with old script system and let 'admin' use new script with few rewards from one box)
------------------------------
We make scripts for ots community. If 90% of OTS admins are newbies we must make scripts for newbies (of course someone should optimize it to learn all newbies HOW TO SCRIPT). If OTS community die, all our scripts will be useless. Making useless scripts is waste of time :>
 
MAAANY actions/uniques are FOR USERS (they can copy map and scripts), of course I could make script with 233748 positions in config file, but it's waste of time.
(in every my script I use new uids/aids)
With my simple script you copy it to your map and it work (tfs 0.3.4pl2).
I know many other scripts from forum without uids/aids, but little change/bug in map/scripts config let players copy items, make mlvl or any other abuse. I hate scripts that let players abuse bug.
@Chipsen
is it when you play first match on football field? or did you teleport anyone from football field (players on field can't logout [no logout tile])?
do you have in config.lua:
saveGlobalStorage = "yes"
?
@Donio
I didn't see any football script in last 1/2 year. I made it from zero for my otses.

its when the match are over ..
the outfit change's back and the score's come up but u are still in the football arena ..
and yes i have ..
saveGlobalStorage = "yes"
 
Back
Top