Price. Posted May 30, 2014 Share Posted May 30, 2014 Well actually i was making a creative job... to spawn peds in random positions and when they got killed they you get wanted point and money ... the problem is i can't make a blip attached to those random positions. Server: Jobtable = { {1315.4921875, -898.7529296875, 39.578125, 228}, {1178.515625, -2036.8623046875, 69.0078125, 228}, {2432.904296875, -1584.7587890625, 13.753595352173, 228}, {475.8759765625, -1279.939453125, 16.483493804932, 228}, {2491.4052734375, -2499.5556640625, 13.655031204224,228} } function table() for index, player in ipairs ( players ) do local Job = unpack(Jobtable[math.random(#Jobtable)]) local myPed = getRandomPed() local x, y, z = getElementPosition( myPed ) local myBlip = createBlip( x, y, z, 1, 0, 0, 0, 255, myPed ) end end function PedMoney ( attacker, attackerweapon, bodypart, loss ) if attacker and getElementType(attacker) == "player" then theTeam = getPlayerTeam ( attacker ) theWL = getPlayerWantedLevel ( source ) theSkin = getElementModel ( attacker ) if (attackerweapon == 22 or attackerweapon == 23 or attackerweapon == 24 or attackerweapon == 25 or attackerweapon == 26 or attackerweapon == 27 or attackerweapon == 28 or attackerweapon == 29 or attackerweapon == 32 or attackerweapon == 30 or attackerweapon == 31 or attackerweapon == 33 or attackerweapon == 34 or attackerweapon == 38 or attackerweapon == 16 ) then if getTeamName( theTeam ) == "Criminal" then theName = getPlayerName ( source ) thePed = getPlayerName ( attacker ) local playeraccount = getPlayerAccount ( attacker ) givePlayerMoney = {math.random (100,500)} setPlayerWantedLevel (source, 1) end end end end addEventHandler ("onPlayerDamage", getRootElement(), PedMoney) note: that blip thingy i added is not working, and that 228 beside positions are the peds idk if that would work, if not a little help :\? Link to comment
Dealman Posted May 30, 2014 Share Posted May 30, 2014 (edited) You've made a multidimensional array which is not indexed, therefore you must usepairs and not ipairs(Would appear you can use both). Here's a quick little 'tutorial' I wrote to assist you, I hope it's easy enough to understand. -- Create a multidimensional array like this; local theTable = { {1315.4921875, -898.7529296875, 39.578125, 228}, {1178.515625, -2036.8623046875, 69.0078125, 228}, {2432.904296875, -1584.7587890625, 13.753595352173, 228}, {475.8759765625, -1279.939453125, 16.483493804932, 228}, {2491.4052734375, -2499.5556640625, 13.655031204224,228} }; function fetchRandomOnStart_Handler() -- Fetch a random array inside the multidimensional array; (As of now, it has 5 arrays, so get a random index between 1 and 5) local randomIndex = theTable[math.random(1, #theTable)]; -- Since the arrays follow the same pattern (X, Y, Z, SkinID), you can fetch specific data like this; local theX = randomIndex[1] -- This gets the first data in the array. local theY = randomIndex[2] -- This gets the second data in the array. local theZ = randomIndex[3] -- You get the idea. local skinID = randomIndex[4] -- It's pretty easy once you get the hang of it -- Then you can output the result, to make sure it works; outputChatBox("X Coordinate: [#FF2626"..tostring(theX).."#BB0000]", 187, 0, 0, true); outputChatBox("Y Coordinate: [#FF2626"..tostring(theY).."#BB0000]", 187, 0, 0, true); outputChatBox("Z Coordinate: [#FF2626"..tostring(theZ).."#BB0000]", 187, 0, 0, true); outputChatBox("Skin ID: [#FF2626"..tostring(skinID).."#BB0000]", 187, 0, 0, true); end addEventHandler("onClientResourceStart", resourceRoot, fetchRandomOnStart_Handler); Edited May 30, 2014 by Guest Link to comment
Price. Posted May 30, 2014 Author Share Posted May 30, 2014 what about the blip? i mean how can i go to that place I must make a blip Link to comment
Dealman Posted May 30, 2014 Share Posted May 30, 2014 You already have the 3 coordinates in the variables theX, theY, theZ. Since I output them with the messages. Link to comment
Price. Posted May 30, 2014 Author Share Posted May 30, 2014 u did output them but... no message gets out neither position , i need blips too bec idk where those pos are nothing in debugscript 3 Link to comment
Dealman Posted May 30, 2014 Share Posted May 30, 2014 They do get the positions, read my code again and try to understand it. We're here to help, not make the entire thing for you. Link to comment
Den. Posted May 30, 2014 Share Posted May 30, 2014 Price, I think you are trying to use what Dealman posted server-side; Dealman's code is a client-side script. If you wish to change it to server-side, then change the event in line 25 to onResourceStart ( instead of onClientResourceStart) and change each outputChatBox in the function fetchRandomOnStart_Handle to fit the server-side arguments. Link to comment
Chronic Posted May 31, 2014 Share Posted May 31, 2014 Try this (client side) local theTable = { {228, 1315.4921875, -898.7529296875, 39.578125}, {228, 1178.515625, -2036.8623046875, 69.0078125}, {228, 2432.904296875, -1584.7587890625, 13.753595352173}, {228, 475.8759765625, -1279.939453125, 16.483493804932}, {228, 2491.4052734375, -2499.5556640625, 13.655031204224} } local peds = { ped = { } } function fetchRandomOnStart_Handler( ) for _, v in ipairs ( theTable ) do local skin, x, y, z = unpack ( v ) peds.ped[v] = createPed ( skin, x, y, z ) createBlipAttachedTo ( peds.ped[v] ) end end addEventHandler("onClientResourceStart", resourceRoot, fetchRandomOnStart_Handler); 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