Jump to content

Ch3ck3r

Members
  • Posts

    10
  • Joined

  • Last visited

Everything posted by Ch3ck3r

  1. The function wasEventCancelled seems to always return false. I found this in the bug tragger but it was resolved in dp2 already. Nevertheless, the following example code reproduces the error on my machine always. function testEvt() outputChatBox(tostring(wasEventCancelled())) if wasEventCancelled() then outputChatBox("evt was cancelled for reason :"..tostring(getCancelReason())) return nil end outputChatBox("cancelling evt") x = cancelEvent(true, "test cancelling") outputChatBox("evt cancelled: "..(x and "yes" or "no")) end function testEvt2() outputChatBox(tostring(wasEventCancelled())) if wasEventCancelled() then outputChatBox("evt was cancelled for reason :"..tostring(getCancelReason())) return nil end outputChatBox("cancelling evt") x = cancelEvent(true, "test cancelling") outputChatBox("evt cancelled: "..(x and "yes" or "no")) end addEventHandler("onPlayerChat", getRootElement(), testEvt) addEventHandler("onPlayerChat", getRootElement(), testEvt2) This is the only resource running on my server for test purpose. If a player writes something it doesn't show up ingame but in the logs. My script produces the following output: false cancelling evt evt cancelled: yes false cancelling evt evt cancelled: yes Glad for any help.
  2. No, that's the problem, it does not disable them from chatting using console and command "say" or "teamsay". I have tested it. The simplest way i found out now is to "overwrite" the command with commandHandlers function chatFromConsole(player, command, ...) local message = table.concat({...}, " ") cancelEvent(true, "Event handled by other functions") if (command == "teamsay") then triggerEvent("onPlayerChat", player, message, 2) else triggerEvent("onPlayerChat", player, message, 1) end end addCommandHandler("say", chatFromConsole) addCommandHandler("teamsay", chatFromConsole) This cancel's the console command and triggers the normal chat handler which handles my chat output
  3. Hi guys, I've scripted a resource that controls my chat. It offers normal chat that reaches just the people nearby, shout chat (reaches people a bit more far away) and out-of-character chat to chat to everybody. I want the players only to be able to chat when they are logged in. I used an event handler on the event "onPlayerChat" and cancelEvent(true) to stop them from chatting when they are not logged in. The problem is, if you press f8 and type in say Hell everybody you can chat even you are not logged in. A simple way is to set "command.say" and "command.teamsay" to false in the acl.xml. But I want these commands to work, when the players are logged in (it is the only way keybinds work properly). Is there a way to achieve this?
  4. Hi, i want to have some weather changing effect in my server. So i scripted the following resource, but it does not work. On resource start, the weather is set correctly as far as i can assess. After the first change, the weather should change every quarter (at minute 00, 15, 30 and 45). But it doesn't do anything. I added the command /weather to change the weather manually and check if it works, but it always says me, that there is already a change happening. I am not able to find the error, any help appreciated (The script is serverside) function startWeatherSim() local id = getRandomWeatherId() if(not setWeatherBlended(id)) then outputDebugString("Changing weather failed with weatherid "..tostring(id), 1) end local minute = getRealTime().minute local toNextQuarter = 15 - (minute%15) setTimer(setTimer, toNextQuarter*60*1000, 1, changeWeather, 15*60*1000, 0) setTimer(changeWeather, toNextQuarter*60*1000, 1) end function changeWeather() weatherid, changing = getWeather() if(changing ~= nil) then outputDebugString("Weather is already changing at the moment"..tostring(weatherid), 1) return false end local id = getRandomWeatherId() if (not setWeatherBlended(id)) then outputDebugString("Changing weather failed with weatherid "..tostring(id), 1) end end function getRandomWeatherId() local id = math.random(1, 255) outputDebugString("Random Weather is "..tostring(id), 3) return id end addEventHandler("onResourceStart", getResourceRootElement(), startWeatherSim) addCommandHandler("weather", changeWeather)
  5. Yeah that'd be quite useful sometimes. At the moment i use something like this, because i am to lazy to write this exports... stuff mysql = exports.database -- and then in function i use mysql:mysql_query("...")
  6. Yep. I came accross i don't need client side mysql anyway. But is there a way to make a function global? So every resource can call it without exports.resource:function ?
  7. Like robhol suggested, i summed up everything in a central resource called 'database' Actually the whole file just overwrites the mysql functions providing the resource parameter automatically. It was quite a boring task to rewrite all mysql function, so if anybody is in need of it, i will post it up on here. Currently it does only work from server-side. Maybe i will do some event based system for handling action with client scripts later.
  8. Hey yeah! That's a good idea. I think i will do it centralized by exported functions. Thanks
  9. Thanks for this information, though i'd have to know this. Now you are mentioning it it came to my mind, that i've stumbled about this damn error in other languages and modules already. Nevertheless i've one question left. It's not really a problem but maybe you got some advice for me. I need to use the same mysql connection in serveral resources. How do i do that in the best way? I tried to pass the mysq_handle with an exported function which didn't worked. By passing the handle between resources it always became a string and was useless. Atm. i solved it by saving the mysql data in settings.xml and create one connection per resource. Isn't there a better way?
  10. Hi guys, i'm relatively new to lua and mta but not so new at scripting in general. I want to create a new gamemode, starting from scratch and ran into my first problem already. I want to use a mysql database and therefor i am checking the database connection on resource start up. This is the relevant piece of code function onGamemodeStart(resource) g_gameMode = resource g_mysqlHandler = mysql_connect("localhost", "mtasa", "------", "mtasa") if(not g_mysqlHandler) then outputDebugString("Could not establish connection to database server", 1) outputConsole("Could not establish connection to database server") outputServerLog("Could not establish connection to database server") shutdown("Could not establish connection to database server") end end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onGamemodeStart) This piece of code does work, indeed. It shuts down my server when the connection can't be established. But i'm missing the debug output. None of the Lines above create a readable Message. Ther is no message in the console nor in the log file neither a debugmessage in the server. I set debugscript to 3 (ingame) and scriptdebugloglevel (in mtaserver.conf) to 3 as well. Any help appreciated Thanks
×
×
  • Create New...