• 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 need some help, tried fixed.....for days xD

Dumeko

New Member
Joined
Apr 7, 2012
Messages
55
Reaction score
0
blue flag plate

lua code
LUA:
 local config = {
redTeam = 3,
blueTeam = 4,
scoreToWin = 10,
redTeamStorage = 2001,
blueTeamStorage = 2002,
redSide = {x=676, y=499, z=7, stackpos=253},
blueSide = {x=744, y=520, z=7, stackpos=253}
}


function onStepIn(cid, item, position, fromPosition)



local CTF = {
fromPos = {x=660, y=495, z=7, stackpos=253},
toPos = {x=765, y=550, z=7, stackpos=253},
deTile = {x=720,y=626,z=7,stackpos=1}}
function TeleportWinners(cid)
for _, pid in ipairs(getPlayersOnline()) do
if isInArea(getPlayerPosition(pid), CTF.fromPos, CTF.toPos) then
doTeleportThing(pid, CTF.deTile, false)
end
end
end


local flagPosRed = {x=676,y=499,z=7,stackpos=0}
local hasFlag = getPlayerStorageValue(cid,2000)
local checkTeam = getPlayerStorageValue(cid,1000)
local checkRedScore = getGlobalStorageValue(2001)
local checkBlueScore = getGlobalStorageValue(2002)
local currentCaps = getPlayerStorageValue(cid,65535)

function checkScore(cid)
local RedScore = getGlobalStorageValue(2001)
local BlueScore = getGlobalStorageValue(2002)
doBroadcastMessage('Current CTF Game Score:\nRed Team: '.. config.scoreToWin - RedScore ..'\nBlue Team: '.. config.scoreToWin - BlueScore ..'\nFlag captures to win: 10.',MESSAGE_STATUS_CONSOLE_ORANGE)
doPlayerSendChannelMessage(cid, false, 'Current CTF Game Score:\nRed Team: '.. config.scoreToWin - RedScore ..'\nBlue Team: '.. config.scoreToWin - BlueScore ..'\nFlag captures to win: 10.',TALKTYPE_CHANNEL_W,11)
end


function more(cid)
local pos = getPlayerPosition(cid)
local Effects = {
{x=pos.x + 1,y=pos.y + 1,z=pos.z},
{x=pos.x - 1,y=pos.y - 1,z=pos.z},
{x=pos.x - 1,y=pos.y + 1,z=pos.z},
{x=pos.x + 1,y=pos.y - 1,z=pos.z},
{x=pos.x + 1,y=pos.y,z=pos.z},
{x=pos.x - 1,y=pos.y,z=pos.z},
{x=pos.x + 2,y=pos.y,z=pos.z},
{x=pos.x - 2,y=pos.y,z=pos.z},
{x=pos.x,y=pos.y + 2,z=pos.z},
{x=pos.x,y=pos.y + 1,z=pos.z},
{x=pos.x,y=pos.y - 1,z=pos.z},
{x=pos.x,y=pos.y - 2,z=pos.z}
}
if getPlayerStorageValue(cid,2000) == 1 then
for i = 1,12 do
doSendMagicEffect(Effects[i], 8)
end
doSendMagicEffect(getPlayerPosition(cid), 28)
doSendAnimatedText(getPlayerPosition(cid), 'FLAG!',math.random(1,255))
addEvent(more, 1000, cid)
else
stopEvent(cid, more)
end
return 1
end
local Team = getPlayerStorageValue(cid,1000)
local hasFlag = getPlayerStorageValue(cid,2000)

if Team == config.redTeam then 
if item.actionid == 100 then
if Team == config.redTeam and hasFlag <= 0 then
addEvent(more, 1000, cid)
doSetItemActionId(item.uid,item.actionid+1)
doSendMagicEffect(getPlayerPosition(cid), 30)
doBroadcastMessage('The red team has stolen the blue team flag!')
doPlayerSendChannelMessage(cid, false, 'Your team has stolen the blue flag!',TALKTYPE_CHANNEL_W,12)
setPlayerStorageValue(cid, 2015, 1)
end
else
doCreatureSay(cid, 'The flag is not at home!', TALKTYPE_ORANGE_1)
end
else
end
if Team == config.blueTeam then
if hasFlag > 0 then
if item.actionid == 100 then 
if checkTeam == config.blueTeam then
addEvent(checkScore, 3000, cid)
doTeleportThing(cid,fromPosition,false)
doBroadcastMessage(''.. getCreatureName(cid) ..' scored 1 point for the blue team')
doPlayerSendChannelMessage(cid, false,''.. getCreatureName(cid) ..' scored 1 point for your team!',TALKTYPE_CHANNEL_W,11)
setPlayerStorageValue(cid, 2000, 0)
setGlobalStorageValue(config.blueTeamStorage, getGlobalStorageValue(2002)-1)
doSendMagicEffect(getPlayerPosition(cid), 27)
doSendAnimatedText(getPlayerPosition(cid), 'Score!',23)
doSetItemActionId(getThingFromPos(flagPosRed).uid,100)
if currentCaps < 1 then
setPlayerStorageValue(cid,65535,1)
else
setPlayerStorageValue(cid,65535,currentCaps+1)
end 
if checkBlueScore == 1 or getGlobalStorageValue(2000) == 3 then
TeleportWinners(cid)
doBroadcastMessage("Blue Team has won the event!")
setGlobalStorageValue(config.blueTeamStorage, 0)
end
end
else
doCreatureSay(cid, 'Your flag must be at home to capture!', TALKTYPE_ORANGE_1)
end
else
doTeleportThing(cid,fromPosition,false)
doPlayerSendCancel(cid, 'Sorry you do not have the flag!')
end
else
end
return 1
end

Red flag plate

lua code
LUA:
local config = {
redTeam = 3,
blueTeam = 4,
scoreToWin = 10,
redTeamStorage = 2001,
blueTeamStorage = 2002,
redSide = {x=676, y=499, z=7, stackpos=253},
blueSide = {x=744, y=520, z=7, stackpos=253}
}


function onStepIn(cid, item, position, fromPosition)



local CTF = {
fromPos = {x=660, y=495, z=7, stackpos=253},
toPos = {x=765, y=550, z=7, stackpos=253},
deTile = {x=720,y=626,z=7,stackpos=1}}
function TeleportWinners(cid)
	for _, pid in ipairs(getPlayersOnline()) do
		if isInArea(getPlayerPosition(pid), CTF.fromPos, CTF.toPos) then
			doTeleportThing(pid, CTF.deTile, false)
		end
	end
end


local flagPosBlue = {x=744,y=523,z=7,stackpos=0}
local hasFlag = getPlayerStorageValue(cid,2015)
local checkTeam = getPlayerStorageValue(cid,1000)
local checkRedScore = getGlobalStorageValue(2001)
local checkBlueScore = getGlobalStorageValue(2002)
local currentCaps = getPlayerStorageValue(cid,65535)

function checkScore(cid)
local RedScore = getGlobalStorageValue(2001)
local BlueScore = getGlobalStorageValue(2002)
doBroadcastMessage('Current CTF Game Score:\nRed Team: '.. config.scoreToWin - RedScore ..'\nBlue Team: '.. config.scoreToWin - BlueScore ..'\nFlag captures to win: 10.',MESSAGE_STATUS_CONSOLE_ORANGE)
doPlayerSendChannelMessage(cid, false, 'Current CTF Game Score:\nRed Team: '.. config.scoreToWin - RedScore ..'\nBlue Team: '.. config.scoreToWin - BlueScore ..'\nFlag captures to win: 10.',TALKTYPE_CHANNEL_W,12)
end



function more(cid)
local pos = getPlayerPosition(cid)
local Effects = {
{x=pos.x + 1,y=pos.y + 1,z=pos.z},
{x=pos.x - 1,y=pos.y - 1,z=pos.z},
{x=pos.x - 1,y=pos.y + 1,z=pos.z},
{x=pos.x + 1,y=pos.y - 1,z=pos.z},
{x=pos.x + 1,y=pos.y,z=pos.z},
{x=pos.x - 1,y=pos.y,z=pos.z},
{x=pos.x + 2,y=pos.y,z=pos.z},
{x=pos.x - 2,y=pos.y,z=pos.z},
{x=pos.x,y=pos.y + 2,z=pos.z},
{x=pos.x,y=pos.y + 1,z=pos.z},
{x=pos.x,y=pos.y - 1,z=pos.z},
{x=pos.x,y=pos.y - 2,z=pos.z}
}
if getPlayerStorageValue(cid,2015) == 1 then
for i = 1,12 do
doSendMagicEffect(Effects[i], 61)
end
		doSendMagicEffect(getPlayerPosition(cid), 65)
		doSendAnimatedText(getPlayerPosition(cid), 'FLAG!',math.random(1,255))
		addEvent(more, 1000, cid)
		else
		stopEvent(cid, more)
		end
		return 1
		end
local Team = getPlayerStorageValue(cid,1000)
local hasFlag = getPlayerStorageValue(cid,2000)

if Team == config.blueTeam then		
	if item.actionid == 100 then
		if Team == config.blueTeam and hasFlag <= 0 then
		addEvent(more, 1000, cid)
		doSetItemActionId(item.uid,item.actionid+1)
		doSendMagicEffect(getPlayerPosition(cid), 61)
		doBroadcastMessage('The blue team has stolen red team flag!')
		doPlayerSendChannelMessage(cid, false, 'Your team has stolen the red flag!',TALKTYPE_CHANNEL_W,12)
		setPlayerStorageValue(cid, 2015, 1)
		end
	else
		doCreatureSay(cid, 'The flag is not at home!', TALKTYPE_ORANGE_1)
	end
else
end
if Team == config.redTeam then
if hasFlag > 0 then
	if item.actionid == 100 then	
		if Team == config.redTeam then
			addEvent(checkScore, 3000, cid)
			doTeleportThing(cid,fromPosition,false)
			doBroadcastMessage(''.. getCreatureName(cid) ..' scored 1 point for the red team!')
			doPlayerSendChannelMessage(cid, false,''.. getCreatureName(cid) ..' scored 1 point for your team!',TALKTYPE_CHANNEL_W,12)
			setPlayerStorageValue(cid, 2000, 0)
			setGlobalStorageValue(config.redTeamStorage, getGlobalStorageValue(2001)-1)
			doSendMagicEffect(getPlayerPosition(cid), 61)
			doSendAnimatedText(getPlayerPosition(cid), 'Score!',10)
			doSetItemActionId(getThingFromPos(flagPosBlue).uid,100)
			if currentCaps < 1 then
				setPlayerStorageValue(cid,65535,1)
				else
				setPlayerStorageValue(cid,65535,currentCaps+1)
			end
			if checkRedScore == 1 or getGlobalStorageValue(2000) == 3 then
				TeleportWinners(cid)
				doBroadcastMessage("Red Team has won the event!")
				setGlobalStorageValue(config.redTeamStorage, 0)
			end
		end
	else
		doCreatureSay(cid, 'Your flag must be at home to capture!', TALKTYPE_ORANGE_1)
	end
else
	doTeleportThing(cid,fromPosition,false)
	doPlayerSendCancel(cid, 'Sorry you do not have the flag!')
end
else
end
return 1
end


i changed some things around

Before changes:
red team capture blue flag, took to red flag plate = scored point (Worked)

Blue team captures red flag, take to blue flag plate = drop flag, no point scored red flag does not return home (didnt work)

After Changes:

Red team captures blue flag takes to red flag plate (Sorry you do not have the flag) (keeps holding the flag)

Blue tame captures red flag takes to blue flag plate (sorry you do not have the flag) (keeps holding the flag)

any idea's or suggestions? i have tried a bunch of different stuff and i dont know what else to try. (im not a scripter at all, but before red team didnt even work xD and i had got that to work somehow) untill i made changes now both teams are stuck holding the flag and cannot score points
 
Back
Top