-
Posts
66 -
Joined
Everything posted by Lergen
-
That did the trick, thanks! I tried this out, but I couldn't get it working. I'll try tinkering with it though. What's the difference between TickCount and Timers that make it more optimized?
-
I have this script here that lets a player spawn a vehicle. I tried adding a timer to it so that there's a two minute cooldown before spawning another vehicle, it's supposed to be on a player-by-player basis but it's still global. Can someone tell me what I'm doing wrong? I'd really appreciate it. local spawnDelayTime = 120000 -- delay time in ms local spawnTimer = { } function carSpawn () if isTimer(spawnTimer[source]) then local timeleft = math.ceil( getTimerDetails(spawnTimer[source])/1000 ) -- Get seconds left from timer if timeleft then local secondString = " second" if timeleft > 1 then secondString = " seconds" end outputChatBox("You may spawn your vehicle again in "..tostring(timeleft)..secondString) return false end end if not (isGuestAccount (getPlayerAccount (source))) and not (isPedInVehicle(source)) then spawnTimer[source] = setTimer(function() spawnTimer[source] = false end,spawnDelayTime,1)
-
Hello, I'm fairly new to this. I'm trying to learn to convert the GTWTurf system (https://github.com/404rq/GTW-RPG/tree/master/[resources]/GTWturf) to use Castillo's gang system (https://community.multitheftauto.com×/index.php?p=resources&s=details&id=1514). I think I have it working, but the turf colors won't update to use the exported gang colors. What am I doing wrong? I'm guessing the problem is in this: local playerGang = getElementData (player, "gang" ) if ( playerGang ) then local r, g, b = unpack ( getGangColor ( playerGang ) ) setRadarAreaColor(area, tonumber(r), tonumber(g), tonumber(b), 175) setRadarAreaFlashing(area, false) setElementData(theTurf, "currAttacker", nil) dbExec(db, "UPDATE turfs SET owner=?, red=?, green=?, blue=? WHERE X=? AND Y=?", gang, r, g, b, tonumber(getElementData(colCuboid,"posx")), tonumber(getElementData(colCuboid,"posy"))) end end, time_to_capture*1000, 1) end end I'm using Sasuke's turfsystem, which does use Castillo's gang system, as a reference: function ( player ) if turfElement[source] and source == turfElement[source][1] then local turf,area,id = unpack( turfElement[source] ) local playerGang = getElementData ( player, "gang" ) local turfGang = executeSQLQuery("SELECT GangOwner FROM Turf_System WHERE Turfs=?", "Turf["..tostring(id).."]" ) if ( turfGang[1].GangOwner == playerGang ) then outputChatBox( messages[2]:format( turfGang[1].GangOwner or "None" ), player, 0, 255, 0, false ) else local playerGang = getElementData ( player, "gang" ) setElementData( source, "warTurf", playerGang ) if ( isTimer ( turfTimer[source][1] ) ) then if isTimer( turfTimer[source][2] ) then killTimer( turfTimer[source][2] ) end return end if ( playerGang ) then local r, g, b = unpack ( getGangColor ( playerGang ) ) -- local r, g, b = 255, 255, 255 setRadarAreaFlashing ( area, true ) if turfGang[1].GangOwner ~= "Nadie" then outputChatBox( messages[3]:format( turfGang[1].GangOwner ), player, 0, 255, 0, false ) else outputChatBox( messages[4], player, 0, 255, 0, false ) end turfTimer[source][1] = setTimer ( function ( ) local players = getGangPlayersInTurf ( turf, playerGang ) setRadarAreaColor ( area, tonumber(r), tonumber(g), tonumber(b), 175 ) for _, player in ipairs ( players ) do outputChatBox( messages[5], player, 0, 255, 0, false ) triggerClientEvent(player, "onTakeTurf", player) givePlayerMoney ( player, 4000 ) executeSQLQuery("UPDATE Turf_System SET GangOwner=?,r=?,g=?,b=? WHERE Turfs=?", playerGang, tonumber(r), tonumber(g), tonumber(b), "Turf["..tostring(id).."]" ) -- setElementData ( turf, "getTurfGang", playerGang ) end setRadarAreaFlashing ( area, false ) end ,120000, 1) end end end end In the debug I get badargument at getelementdata [expected element at argument 1, got nil]. I'd greatly appreciate any advice.
-
That's the problem, it isn't a table and I can't modify it because the code is compiled. https://community.multitheftauto.com/index.php?p=resources&s=details&id=1514 The reason I'm looking at turf system is because it's somehow still managing to call the colors despite that (when a player takes over a turf, it changes to their gang's color). That's why I'm starting to think the SQL is what's allowing that script to call the colors and why mine isn't working. I don't know what else the problem could be, but I don't know. I could be way off here.
-
I'm almost positive I've figured out why it's not calling the colors. It's the SQL - I didn't add it to my script. This is what the entire Turf script looks like that I've been using for reference: addEventHandler("onResourceStart", resourceRoot, function() executeSQLQuery("CREATE TABLE IF NOT EXISTS Turf_System ( Turfs TEXT, GangOwner TEXT, r INT, g INT, b INT)") -- local check = executeSQLQuery("SELECT * FROM Turf_System" ) if #check == 0 then for i=1,#turfPos do executeSQLQuery("INSERT INTO Turf_System(Turfs,GangOwner,r,g,b) VALUES(?,?,?,?,?)", "Turf["..tostring(i).."]", "Nadie", 0, 255, 0) end elseif #check > 1 then for i = #check, #turfPos do executeSQLQuery("INSERT INTO Turf_System(Turfs,GangOwner,r,g,b) VALUES(?,?,?,?,?)", "Turf["..tostring(i).."]", "Nadie", 0, 255, 0) end end for i,v in ipairs(turfPos) do local sqlData = executeSQLQuery("SELECT * FROM Turf_System WHERE Turfs=?", "Turf["..tostring(i).."]") local turfCol = createColCuboid(unpack(v)) setElementData(turfCol, "getTurfGang", sqlData[1].GangOwner) local turfArea = createRadarArea(v[1], v[2], v[4], v[5], sqlData[1].r, sqlData[1].g, sqlData[1].b, 175) turfElement[turfCol] = {turfCol, turfArea, i} turfTimer[turfCol] = {} end outputDebugString( messages[1] ) end ) addEventHandler ('onPlayerLogin', root, function ( player ) local playerGang = getElementData ( player, "gang" ) if ( playerGang ) then local r, g, b = unpack ( getGangColor ( playerGang ) ) setPlayerNametagColor(player, tonumber(r), tonumber(g), tonumber(b)) end end ) addEventHandler ( "onColShapeHit", root, function ( player ) if turfElement[source] and source == turfElement[source][1] then local turf,area,id = unpack( turfElement[source] ) local playerGang = getElementData ( player, "gang" ) local turfGang = executeSQLQuery("SELECT GangOwner FROM Turf_System WHERE Turfs=?", "Turf["..tostring(id).."]" ) if ( turfGang[1].GangOwner == playerGang ) then outputChatBox( messages[2]:format( turfGang[1].GangOwner or "None" ), player, 0, 255, 0, false ) else local playerGang = getElementData ( player, "gang" ) setElementData( source, "warTurf", playerGang ) if ( isTimer ( turfTimer[source][1] ) ) then if isTimer( turfTimer[source][2] ) then killTimer( turfTimer[source][2] ) end return end if ( playerGang ) then local r, g, b = unpack ( getGangColor ( playerGang ) ) -- local r, g, b = 255, 255, 255 setRadarAreaFlashing ( area, true ) if turfGang[1].GangOwner ~= "Nadie" then outputChatBox( messages[3]:format( turfGang[1].GangOwner ), player, 0, 255, 0, false ) else outputChatBox( messages[4], player, 0, 255, 0, false ) end turfTimer[source][1] = setTimer ( function ( ) local players = getGangPlayersInTurf ( turf, playerGang ) setRadarAreaColor ( area, tonumber(r), tonumber(g), tonumber(b), 175 ) for _, player in ipairs ( players ) do outputChatBox( messages[5], player, 0, 255, 0, false ) triggerClientEvent(player, "onTakeTurf", player) givePlayerMoney ( player, 4000 ) executeSQLQuery("UPDATE Turf_System SET GangOwner=?,r=?,g=?,b=? WHERE Turfs=?", playerGang, tonumber(r), tonumber(g), tonumber(b), "Turf["..tostring(id).."]" ) -- setElementData ( turf, "getTurfGang", playerGang ) end setRadarAreaFlashing ( area, false ) end ,120000, 1) end end end end ) addEventHandler ( "onColShapeLeave", root, function( player ) if turfElement[source] and source == turfElement[source][1] then if isTimer( turfTimer[source][1] ) then local aGang = getElementData( source, "warTurf" ) local ps = getGangPlayersInTurf( source, aGang ) if #ps == 0 then outputChatBox( messages[6], player, 255, 0, 0 ) turfTimer[source][2] = setTimer( function(source, aGang) if isTimer(turfTimer[source][1]) then killTimer(turfTimer[source][1]) end setRadarAreaFlashing(turfElement[source][2], false) for _, v in ipairs( getElementsByType("player") ) do if getElementData(v, "gang") == aGang then outputChatBox(messages[7], v, 255, 0, 0) end end end , 20000, 1, source, aGang) end end end end ) function getGangPlayersInTurf( turf, gang ) -- element, string if turf and gang then local players = getElementsWithinColShape ( turf, "player" ) local gPla = {} for _, v in ipairs( players ) do if getElementData(v, "gang") == gang then table.insert(gPla, v) end end return gPla end end function getGangColor(gangName) return exports[ "gang_system" ]:getGangData ( gangName, "color" ) end I'm still learning, but I think what's happening is that it's getting the gang colors and turning them into the table that's needed for the unpack (hence the "bad argument #1 to 'unpack' (table expected, got boolean)) error in my own script. But I don't know where to go from here. Do I modify the SQL so that it just gets colors with none of the turf stuff or is there a simpler way of doing this?
-
Still working on this, but no luck. What changes in a restart that would make it work when it wouldn't before? I'm starting to think it's the event 'onPlayerJoin' that may be messing it up somehow.
-
OK. Possibly(?) some progress. local r,g,b = exports.gang_system:getGangData ( gangName, "color" ) Returns: "bad argument at 'setPlayerNametagColor' [expected number at argument 2, got nil]. using it this way, it can't get colors from the gang system. I feel like reiterating that this function joinHandler(player) if not player then player = source end local gangName = getElementData(player, "gang") local r, g, b = unpack(getGangColor(gangName)) setPlayerNametagColor(player, tonumber(r), tonumber(g), tonumber(b)) g_PlayerData[player] = { vehicles = {}, settings={} } g_PlayerData[player].blip = createBlipAttachedTo(player, 0, 2, tonumber(r), tonumber(g), tonumber(b)) addEventHandler("onFreeroamLocalSettingChange",player,onLocalSettingChange) if getOption('welcometextonstart') then outputChatBox('Welcome to Freeroam', player, 0, 255, 0) end end addEventHandler('onPlayerJoin', root, joinHandler) actually -works- it get the gang colors, and displays them like I want it to, the only thing is that freeroam needs to be restarted for it to work. It outputs only this one error when a player connects: "bad argument #1 to 'unpack' (table expected, got boolean). Could this be the problem?
-
Thanks. I got "Bad argument at setPlayerNametagColor [Expected number at argument 2, got nil] I'm at a loss. Could the problem be somewhere else in the freeroam script?
-
I appreciate your help. That code didn't output any errors, but it unfortunately didn't work. This is what the default freeroam script looks like: function joinHandler(player) if not player then player = source end local r, g, b = math.random(50, 255), math.random(50, 255), math.random(50, 255) setPlayerNametagColor(player, r, g, b) g_PlayerData[player] = { vehicles = {}, settings={} } g_PlayerData[player].blip = createBlipAttachedTo(player, 0, 2, r, g, b) addEventHandler("onFreeroamLocalSettingChange",player,onLocalSettingChange) if getOption('welcometextonstart') then outputChatBox('Welcome to Freeroam', player, 0, 255, 0) outputChatBox('Press F1 to show/hide controls', player, 0, 255, 0) end end addEventHandler('onPlayerJoin', root, joinHandler) And this is my modified version which should just be changing blip/nametag color: function joinHandler(player) if not player then player = source end local gangName = getElementData(player, "gang") local r, g, b = unpack(getGangColor(gangName)) setPlayerNametagColor(player, tonumber(r), tonumber(g), tonumber(b)) g_PlayerData[player] = { vehicles = {}, settings={} } g_PlayerData[player].blip = createBlipAttachedTo(player, 0, 2, tonumber(r), tonumber(g), tonumber(b)) addEventHandler("onFreeroamLocalSettingChange",player,onLocalSettingChange) if getOption('welcometextonstart') then outputChatBox('Welcome to Freeroam', player, 0, 255, 0) end end addEventHandler('onPlayerJoin', root, joinHandler) This works like it should, but freeroam needs to be restarted for each new person that joins for the blip/nametag to show up. I'm just not sure what's breaking here.
-
Thanks, I messed around with it a bit and almost have it working! The nametags and blips show like they're supposed to, but only if I restart the freeroam gamemode each time a new person joins, otherwise they don't show at all. In other words, only on restarting freeroam whenever somebody joins can I get it to work. I'm not sure if it's related but I get this error in debug: "server.lua 131:bad argument #1 to 'unpack' (table expected, got boolean) Line 131 is line 6 here. function joinHandler(player) if not player then player = source end local gangName = getElementData(player, "gang") local r, g, b = unpack(getGangColor(gangName)) setPlayerNametagColor(player, tonumber(r), tonumber(g), tonumber(b)) g_PlayerData[player] = { vehicles = {}, settings={} } g_PlayerData[player].blip = createBlipAttachedTo(player, 0, 2, tonumber(r), tonumber(g), tonumber(b)) addEventHandler("onFreeroamLocalSettingChange",player,onLocalSettingChange) if getOption('welcometextonstart') then outputChatBox('Welcome to Freeroam', player, 0, 255, 0) end end addEventHandler('onPlayerJoin', root, joinHandler) function getGangColor(gangName) return exports[ "gang_system" ]:getGangData ( gangName, "color" ) end I'm just using the default freeroam server script. Was there something I forgot to add?
-
Setting it as its own stand-alone script rather than trying to incorporate it into the Freeroam script, the only problem returned is the "Client (name) triggered event onServerCall, but event is not added serverside." one. I'm not sure what this means though.
-
Hey, thanks! I tried it out, but sadly it doesn't seem to work. I got these error messages: ')' expected near '∩' Client (name) triggered serverside event onloadedAtClient but event is not added serverside "Client (name) triggered event onServerCall, but event is not added serverside. Where should I go from here?
-
Thank you, although I'm trying to get it working with Castillo's gang system rather than teams. Turfsystem can utilize it for ColShapes so I would think it should be possible to set it for Blips and/or NametagColor as well, but I'm just too much of a novice to figure out how it works. local playerGang = getElementData ( player, "gang" ) if ( playerGang ) then local r, g, b = unpack ( getGangColor ( playerGang ) ) end setPlayerNametagColor(player, tonumber(r), tonumber(g), tonumber(b)) g_PlayerData[player] = { vehicles = {}, settings={} } g_PlayerData[player].blip = createBlipAttachedTo(player, 0, 2, r, g, b) function getGangColor(gangName) return exports[ "gang_system" ]:getGangData ( gangName, "color" ) end Something I tried. This doesn't output any errors but it doesn't work either.
-
Is this possible? What I'm trying to achieve is having player blips in freeroam be the color of whatever gang they're in, I would assume it would be since turfs are capable of using gang colors but I'm not sure if the same can be done for blips. I'm using Castillo's gang system. Any advice?
-
An additional problem - it looks like the flag doesn't respawn at all in CTF, even after it's been captured.
-
Hello, I've just recently setup a server so I'm pretty new to this whole thing. I've read through the wiki but I'm still not sure how to approach these problems, I'd really appreciate any help or advice on this. These are from the default gamemodes bundled with MTA. If you start Assault from another gamemode (like Play) then there's a peculiar bug where on death, you won't respawn. The only way to fix this is by either relogging or changing teams with F3. It doesn't seem to show any errors in debug and after the relog/team change it doesn't happen again. I'm not sure what causes this. My other issue is that in CTF, if the flag is dropped, it doesn't respawn after a set time. Normally this wouldn't be a problem but on a map like tbd, it's possible to ruin the match if the flag carrier falls off the cliff. Is there any way to have it revert to its starting position sometime after being dropped? I'm guessing setTimer is used but I'm unsure of how to implement it.