-
Posts
667 -
Joined
-
Last visited
-
Days Won
4
Everything posted by Mr.Loki
-
Edit the file called "Lua MTA.tmLanguage" inside of the mta package.
-
Client triggered server side event, but event is not added serverside
Mr.Loki replied to jessiepinkman's topic in Scripting
Line 3 change resourceRoot to root -
Client triggered server side event, but event is not added serverside
Mr.Loki replied to jessiepinkman's topic in Scripting
Then just change getRootElement() to localPlayer and plr and thePlayer to source -
Client triggered server side event, but event is not added serverside
Mr.Loki replied to jessiepinkman's topic in Scripting
You have "plr" and "thePlayer" they are not defined as far as what I can see in the code. Who is plr and who is thePlayer? I'm guessing that plr = player sending money and thePlayer = player receiving money If so then you should set the source of the event to the localPlayer by changing getRootElement() to LocalPlayer in line 23 Then add that "el" variable to 1 of the arguments along with payment at line 23 so it would look like: localPlayer, el, payment) Next in your server event change "plr" to source which will be the localPlayer and add "thePlayer" right before payment in line 3 as a function parameter it would look like: function(thePlayer,payment) -
Client triggered server side event, but event is not added serverside
Mr.Loki replied to jessiepinkman's topic in Scripting
mysql = exports.mysql addEvent("getPlayerCredits",true) addEventHandler("getPlayerCredits", resourceRoot, function (payment) if getElementData(plr, "delivered") == true then exports.global:giveMoney(thePlayer,payment) outputChatBox("OK!",root,0,255,0) return end end) Line 3 script_s addEventHandler("getPlayerCredits", resourceRoot, payment should be addEventHandler("getPlayerCredits", resourceRoot, function(payment) the reason for the error is because you didnt have a comma after payment which is still wrong syntax btw. TIP: You should use an editor that shows simple errors in Lua -
A vector3 holds 3 values and can be declared by using: v = Vector3() It's great for storing positions. (Which I use a lot) Using the above example would create an empty Vector returning (0,0,0) to access the values in the vector we use variables x,y,z: x = v.x y = v.y z = v.z -- x = 0 -- y = 0 -- z = 0 You can even set the values of the vector middleOfMap = Vector3(0,0,-3) To replace "getDistanceBetweenPoints3D" using this method you'd need to minus 1 vector from another and use the ".length" variable: distance = (v-middleOfMap).length The value returned is always absolute so it never goes below 0, meaning it does not matter the order in which you subtract them. which is the same as: direction = (v-middleOfMap) distance = abs(sqrt(direction.x*direction.x+direction.y*direction.y+direction.z*direction.z)) This example gets the distance between 2 players local pos1 = getRandomPlayer( ).position local pos2 = getRandomPlayer( ).position local distance = (pos1-pos2).length print(distance) Also you should check out OOP
-
This is for dayz... please read the topic carefully
-
@Mohamed Asad What's wrong? I think you are going to have to be more specific about this..
-
This isn't tested but I think it should work if you are using the default Dayz event names. If not just change it to match your gamemode. This code does not need to go directly into the Dayz gamemode so just create a new resource with it. I explained every step so it should be easy to follow along and understand what's happening. This is SERVER sided. Been a while since I made anything for Dayz so don't kill me if it doesn't work. Not saying that you SHOULD use this code just giving you an idea of how I'd do it. function manageBounty( ) -- Create a table with all the players in the server. local plrs = getElementsByType "player" -- Go through each player in the table. for i=1,#plrs do local p=plrs[i] local logedin = getPlayerAccount( p ) -- Check if player is loged in.(No need to check guest acc because dayz...) if logedin then local hasBounty = getElementData( p, "Bounty" ) local humanity = getElementData( p, "humanity" ) -- If the player's humanity is less than or equals -6000 and does not have a bointy on his head give him 1 then announce it to the server. if not hasBounty and humanity <= -6000 then setElementData(p, "Bounty", true) outputChatBox ("Kill "..getPlayerName(p).." to get 2500 Tokens!") end end end end -- execute the manageBounty function every 7 seconds.(Do not go lower than 2 seconds.) setTimer( manageBounty, 7000, 0) function rewardBounty( killer,headshot,weapon ) -- Check if "killer" is a player. if killer and type(killer) == "player" then local hasBounty = getElementData( source, "Bounty" ) -- Check if player who died had a bounty. if hasBounty then --Your code here to reward "killer" with tokens! -- Send a message to the server that someone has collected the bounty. outputChatBox (getPlayerName(killer).." collected the bounty on "..getPlayerName(source).."'s head.") -- Remove the bounty from the dead player. setElementData(source, "Bounty", false) end end end addEventHandler("kilLDayZPlayer",root,rewardBounty) -- Command to list all the players that have a bounty and the current humanity. addCommandHandler( "bounty", function( plr ) local plrs = getElementsByType "player" for i=1,#plrs do local p=plrs[i] if getElementData(p, "Bounty") then outputChatBox( getPlayerName(p).." #ffffffHumanity:"..getElementData(p, "humanity"), plr, 255, 255, 255, true ) end end end )
-
Try something like this. This is a Server script. function RespawnStuff( ... ) -- Code to respawn stuff end addCommandHandler( "respawnall", function( plr, cmd, sec ) local time = sec and (sec * 1000) or 1000 setTimer( RespawnStuff, time, 1, ... ) outputChatBox( "Stuff will be respawned in "..sec.." seconds." ) end)
-
Are you using any script to change the weapons?
-
I still am not sure of what you are trying to accomplish. Do you want to change the ped/player's weapon? If so then use this setPedWeaponSlot.
-
Please read the guidelines before posting.
-
Try using Sublime Text 3 with Lua Linter addon. Works like a charm
-
I modified the custom function a bit... but this is what it does. I hope this helps. Also added another arg to set the background colour or hide it. https://gfycat.com/UnimportantHiddenIberianmole function Draw() local vehs = getElementsByType("vehicle") local players = getElementsByType("player") for k,v in ipairs(vehs) do if getPedOccupiedVehicle( localPlayer ) ~= v then dxDrawTextOnElement (v, getVehiclePlateText(v), 0.75, _, _, _, _, _, 2, _, tocolor(0,0,0,255)) end end for k,v in ipairs(players) do if v ~= localPlayer then dxDrawTextOnElement (v, getPlayerName(v), _, _, _, _, _, _, 1) end end end addEventHandler ("onClientRender", getRootElement(), Draw) function dxDrawTextOnElement(TheElement,text,height,distance,R,G,B,alpha,size,font,bgColor,checkBuildings,checkVehicles,checkPeds,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement) local x, y, z = getElementPosition(TheElement) local x2, y2, z2 = getCameraMatrix() local distance = distance or 20 local height = height or 1 local checkBuildings = checkBuildings or true local checkVehicles = checkVehicles or false local checkPeds = checkPeds or false local checkObjects = checkObjects or true local checkDummies = checkDummies or true local seeThroughStuff = seeThroughStuff or false local ignoreSomeObjectsForCamera = ignoreSomeObjectsForCamera or false local ignoredElement = ignoredElement or nil if (isLineOfSightClear(x, y, z, x2, y2, z2, checkBuildings, checkVehicles, checkPeds , checkObjects,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement)) then local sx, sy = getScreenFromWorldPosition(x, y, z+height) if(sx) and (sy) then local distanceBetweenPoints = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) if(distanceBetweenPoints < distance) then if bgColor then local tw = dxGetTextWidth( text, size or 1, font or "arial" ) local tw = tw-((distanceBetweenPoints / distance)*(tw/2)) local th = (12*size)-((distanceBetweenPoints / distance)*12) dxDrawRectangle( sx-(tw/2)-1, sy-(th/2)-1, tw+3, th+3 , bgColor) end dxDrawText(text, sx+2, sy+2, sx, sy, tocolor(R or 255, G or 255, B or 255, alpha or 255), (size or 1)-(distanceBetweenPoints / distance), font or "arial", "center", "center") end end end end
-
The problem is that the there is no data for "deaths" on the player so it is returning a boolean( a true/false value ) which would be false in your case. function KDShow(player) local deaths = getElementData ( localPlayer, "deaths" ) dxDrawText(deaths or 0, 86, 367, 193, 388, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, false, false, false) end What I've done is made a simple check to see if deaths == false. If deaths == false it will use the or operator and return 0. If deaths == a number or anything, it will show that value of "deaths" instead. local deaths = (getElementData ( localPlayer, "deaths" ) or 0)
-
Make the texture transparent
-
engineLoadTXD engineLoadDFF engineImportTXD engineReplaceModel There is a search bar on the forum.
-
show us the "loadTurfs" function because there's nothing to work with here.
-
addCommandHandler("sendmoney",function(player,cmd,targetPlayerName,money) money = tonumber(money) and math.floor(tonumber(money)) or nil if not (targetPlayerName) or not (money) then outputChatBox("use /" .. cmd .. " [Player] [Amount]",player,255,0,0,true) else local targetPlayer = getPlayerFromName (targetPlayerName) if targetPlayer then if (targetPlayer==player) then outputChatBox(" You cant give money to yourself.",player,255,0,0,true) elseif money <= 0 then outputChatBox(" Minimum ammount is 1.",player,255,0,0,true) elseif getPlayerMoney(player) >= money and money > 0 and targetPlayer~=player then takePlayerMoney(player,money) givePlayerMoney(targetPlayer,money) outputChatBox ( "You gave " .. targetPlayerName .. " " .. money .. "$", player, 0, 255, 0, true) -- THIS LINE outputChatBox ( "" .. player .. "gave you " .. money .. "$", targetPlayer, 0, 255, 0, true ) -- THIS LINE else outputChatBox(" You dont have enough money.",player,177,9,45,true) end end end end) You have to read through your code carefully.
-
You already calculated the distance so all you have to do it check if the distance is less than 50 or 5 function dxDrawImageOnElement() local playerPosition = {getElementPosition(localPlayer)} local elementPosition = {getElementPosition(data.element)} local distance = math.floor(getDistanceBetweenPoints3D(elementPosition[1], elementPosition[2], elementPosition[3], playerPosition[1], playerPosition[2], playerPosition[3])) local coords = {getScreenFromWorldPosition(elementPosition[1], elementPosition[2], elementPosition[3]+0.3)} local clear = isLineOfSightClear(elementPosition[1], elementPosition[2], elementPosition[3], playerPosition[1], playerPosition[2], playerPosition[3], false, false, false, false, true, false, false, nil) if coords[1] and clear and distance <= 50 then -- Check if the distance is less than "50" dxDrawText(distance.."m", coords[1], coords[2] + sy/38, coords[1], coords[2], tocolor(255, 255, 255, 255), 2, "default-bold", "center", "center", false, false) dxDrawImage(coords[1], coords[2], data.width, data.height, data.image..".png", 0, 0, 0, tocolor(255, 255, 255, 255), false) end end Since you are scripting with tables like this I suggest you learn to use OOP and Vectors it's very similar and much simpler to use. For example: function dxDrawImageOnElement() local player = localPlayer.position local elem = Vector3(getElementPosition(data.element)) local distance = (player-elem).length local coords = Vector2(getScreenFromWorldPosition(elem+Vector3(0,0,0.3))) local clear = isLineOfSightClear(elem, player, false, false, false, false, true, false, false, nil) if coords.x and clear then dxDrawText(distance.."m", coords.x, coords.y + sy/38, coords.x, coords.y, tocolor(255, 255, 255, 255), 2, "default-bold", "center", "center", false, false) dxDrawImage(coords.x, coords.y, data.width, data.height, data.image..".png", 0, 0, 0, tocolor(255, 255, 255, 255), false) end end