Dzsozi (h03) Posted April 24, 2014 Share Posted April 24, 2014 Hello everybody, today I made a countdown script and I tried to add an export function, but it's not working for some reason. I think I've done everything well, but here's my code: meta: client: local sx, sy = guiGetScreenSize () function startCountDown ( source ) guiSetVisible ( imagecount, false ) imagecount = guiCreateStaticImage ( (670 / 1600) * sx, (140 / 1300) * sy, (250 / 1600) * sx, (220 / 1300) * sy,"images/3.png",false) setTimer ( Countdown2, 1300, 1 ) local sound = playSound("tick.mp3", false) end function Countdown2 ( source ) guiSetVisible ( imagecount, false ) imagecount = guiCreateStaticImage( (670 / 1600) * sx, (140 / 1300) * sy, (250 / 1600) * sx, (220 / 1300) * sy,"images/2.png",false) setTimer ( Countdown1, 1300, 1 ) local sound = playSound("tick.mp3", false) end function Countdown1 ( source ) guiSetVisible ( imagecount, false ) imagecount = guiCreateStaticImage( (670 / 1600) * sx, (140 / 1300) * sy, (250 / 1600) * sx, (220 / 1300) * sy,"images/1.png",false) setTimer ( Countdown0, 1300, 1 ) local sound = playSound("tick.mp3", false) end function Countdown0 ( source ) guiSetVisible ( imagecount, false ) imagecount = guiCreateStaticImage( (670 / 1600) * sx, (140 / 1300) * sy, (250 / 1600) * sx, (220 / 1300) * sy,"images/go.png",false) setTimer ( CountdownEnd, 3000, 1 ) local sound = playSound("go.mp3", false) end function CountdownEnd ( source ) guiSetVisible ( imagecount, false ) end addCommandHandler ( "cd", startCountDown ) addEvent("startCountDown", true) addEventHandler("startCountDown", startCountDown) server: function startCountDown(player) if isElement(player) then triggerClientEvent(player, "startCountDown", getRootElement()) end end the way I tried to call it in server side script: exports.countdown:startCountDown(source) What's the problem with my codes? Link to comment
pa3ck Posted April 24, 2014 Share Posted April 24, 2014 Well, I know if you don't define the type ( client, server ) at the script, it's gonna be server by default, but I don't know if it works like that with an export function. Try to put type="server" and see if it works. Also, I'd put an 'else' statement after the 'isElement' just to make things easier and see if the passed argument is an element or not. Link to comment
arezu Posted April 24, 2014 Share Posted April 24, 2014 Debug your code using outputDebugString. Put one in server side startCountDown outside the if statement and one inside, and then put another one in client side startCountDown. My guess is that 'source' that you call the function with is not an element. Link to comment
Dzsozi (h03) Posted April 24, 2014 Author Share Posted April 24, 2014 Still not working. And debugscript shows nothing about this. Link to comment
Vinctus Posted April 24, 2014 Share Posted April 24, 2014 make the type as "server" on first one, try after that <meta> <script src="countdownC.lua" type="client" /> <script src="countdownS.lua" type="server" /> <file src="images/1.png" /> <file src="images/2.png" /> <file src="images/3.png" /> <file src="images/go.png" /> <file src="go.mp3" /> <file src="tick.mp3" /> <export function="startCountDown" type="server" /> <export function="startCountDown" type="client" /> </meta> what is the clientside for anyway? Link to comment
Dzsozi (h03) Posted April 24, 2014 Author Share Posted April 24, 2014 make the type as "server" on first one, try after that <meta> <script src="countdownC.lua" type="client" /> <script src="countdownS.lua" type="server" /> <file src="images/1.png" /> <file src="images/2.png" /> <file src="images/3.png" /> <file src="images/go.png" /> <file src="go.mp3" /> <file src="tick.mp3" /> <export function="startCountDown" type="server" /> <export function="startCountDown" type="client" /> </meta> what is the clientside for anyway? I've already wrote it there. But it's working on client side, tested it with a command, but in server side it's not working. Link to comment
pa3ck Posted April 24, 2014 Share Posted April 24, 2014 function startCountDown(player) if isElement(player) then triggerClientEvent(player, "startCountDown", player) else outputDebugString ( "Bad element pointer @ startCountDown", 0 ) end end Link to comment
Dzsozi (h03) Posted April 24, 2014 Author Share Posted April 24, 2014 Yes, now when I write the command which is in server side now it writes this: countdown/countdownS.lua:5: Bad element pointer @ startCountDown Link to comment
arezu Posted April 24, 2014 Share Posted April 24, 2014 You should learn how to debug your scripts and check the documentation better; there are tutorials on how to debug at this forum. Also, https://wiki.multitheftauto.com/wiki/AddCommandHandler Command handlers do not have a source, only events do, and also these are the parameters: player playerSource, string commandName, [string arg1, string arg2, ...] Check the example on wiki. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now