Jump to content

UTurn

Members
  • Posts

    15
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

UTurn's Achievements

Square

Square (6/54)

0

Reputation

  1. Well I've solved it. I looked hard for the source of my problem, but in the wrong places. An error where the map data was loaded (which I failed to provide here, bad move to ommit when seeking help) was giving me an incorrect Z position. So I couldn't see the marker, but I could hit it's area. Well, atleast posting this question caused me to look even harder
  2. I'm working on a police script, and I'm creating markers/blips on the client of the police officer to show him where to jail the player. Heres the event handlers that create/destroy the markers and blips, and checks for the hit: -- -- Creates all the jail markers/blips when a cop gets an arrest. -- addEventHandler("showJailMarkers", localPlayer, function (jailPoints) for k,jPoint in ipairs(jailPoints) do local x = jPoint[1] local y = jPoint[2] local z = jPoint[3] if x and y and z then local jailMark = createMarker(x,y,z, "cylinder", 4.0, 50,130,200, 195) setElementData(jailMark, "isJailMark", true) setElementDimension(jailMark, 0) table.insert(JAIL_MARKS, jailMark) table.insert(JAIL_BLIPS, createBlip(x,y,0, 30, 2.0, 255,0,0,255, 0, 400.0)) end end end ) -- -- Destroys all the jail markers/blips when a cop no longer has prisoners. -- addEventHandler("hideJailMarkers", localPlayer, function () for key,jailMark in pairs(JAIL_MARKS) do if isElement(jailMark) then destroyElement(jailMark) end end for key,jailBlip in pairs(JAIL_BLIPS) do if isElement(jailBlip) then destroyElement(jailBlip) end end end ) -- -- Jails all prisoners when the captor enters the jail marker. -- addEventHandler("onClientMarkerHit", root, function (hitPlayer, dimensionMatch) if (hitPlayer ~= localPlayer) then return end if (getElementData(source, "isJailMark") == true) then triggerServerEvent("policeJailPrisoners", resourceRoot) end end ) I use data from the map file to get the locations to place blips and markers. Everything else works fine, i can arrest the player, walk into where the marker should be, and it sends him to jail. But when I arrest a player, the blip shows up on my client, but not the marker. I can't use `setElementVisibleTo` because I don't want to create the markers on the serverside. I've tried using `setElementDimension(jailMark, 0)` to ensure the marker is in the same dimension but it still is invisible. If it makes any difference here's where the event to create the markers gets triggered on the server: -- -- Forces a player arrested with the baton to follow is captor. -- addEventHandler("policePlayerArrested", resourceRoot, function (captor) local prisoner = client exports.AC_message:outputTopBar("Damn son! You got arrested by "..getPlayerName(captor), prisoner, 255,0,0) exports.AC_message:outputTopBar("You've placed "..getPlayerName(prisoner).." under police custody.", captor, 50,130,200) -- Disable the prisoners GTA controls. toggleAllControls(prisoner, false, true, false) triggerClientEvent(prisoner, "onWindowOpen", prisoner, false) setPedWeaponSlot(prisoner, 0) -- Set the players arrest data and force him to follow his captor. setElementData(prisoner, "isArrested", true) setElementData(prisoner, "arrestedBy", captor) forcePrisonerFollow(captor, prisoner) -- If the new prisoner is a cop free all his prisoners. if exports.gtc_jobsys:isAssignedJob(prisoner, "Police") then freeAllPrisoners(prisoner) end -- If this is the cops first arrest, show the jail markers. local prisonerCount = getPrisonerCount(captor) if (prisonerCount == 1) then triggerClientEvent(captor, "showJailMarkers", captor, exports.GTC:getJailmarkPoints()) end end ) What could I be doing wrong? If the blips show I don't see why the markers wouldn't show.
  3. Knew it had to be something simple I was missing I guess I had myself convinced that the client only dealt with the local player so I treated it as if (hitPlayer == localPlayer) Lol anyways thanks!
  4. I have a job system script I wrote, and it has a window that comes up when you enter a marker, everything works fine when i test it, no debugscript errors/warnings, no errors in the console. But I just tested with a second client on my PC using VMWare player, and when I went into the marker on the second client and took the job, the window was showing on the first client as well, even though it previously was not and I was in a completely different area. At first, I thought it might be that I was using VMWare player, but then I remembered a time when I first started scripting. I had made a simple login system base completely off of the tutorial found at the wiki. I tested it with another friend who lives in a different state, and when he joined the login form would show on my screen, and the other way around as well. So I don't think testing with a VM had anything to do with it. Anyways, I can't for the life of me find anything wrong with my script. I created all the GUI elements for the window in the "onClientResourceStart" event handler, and hid the window for later use. That's what the wiki says should be done aswell. I'm gonna post the entire clientside script, and if none of you can find a problem either, then maybe someone could just give me a general outline of what you yourself would do when creating a GUI that doesn't have this problem. employ_c.lua --[[ employ_c.lua - Enables players to accept a job by approaching a Job NPC. --]] GUIEditor = { button = {}, window = {}, label = {}, memo = {} } -- -- Prevent Non Playable Characters from being damaged/killed. -- function cancelNpcDamage() if (getElementData(source, "isNpc") == true) then cancelEvent() end end -- -- Create the job employment GUI and hide it for later. -- addEventHandler("onClientResourceStart", resourceRoot, function () addEventHandler("onClientPedDamage", root, cancelNpcDamage) GUIEditor.window[1] = guiCreateWindow(0.36, 0.36, 0.25, 0.38, "GTC Employment", true) guiWindowSetMovable(GUIEditor.window[1], false) guiWindowSetSizable(GUIEditor.window[1], false) GUIEditor.label[1] = guiCreateLabel(0.03, 0.08, 0.94, 0.14, "", true, GUIEditor.window[1]) guiSetFont(GUIEditor.label[1], "sa-header") guiLabelSetHorizontalAlign(GUIEditor.label[1], "center", false) GUIEditor.memo[1] = guiCreateMemo(0.03, 0.24, 0.94, 0.61, "", true, GUIEditor.window[1]) guiMemoSetReadOnly(GUIEditor.memo[1], true) GUIEditor.button[1] = guiCreateButton(0.06, 0.88, 0.39, 0.08, "Accept Job", true, GUIEditor.window[1]) addEventHandler("onClientGUIClick", GUIEditor.button[1], onJobAccepted, false) GUIEditor.button[2] = guiCreateButton(0.55, 0.88, 0.39, 0.08, "Close Window", true, GUIEditor.window[1]) addEventHandler("onClientGUIClick", GUIEditor.button[2], hideJobWindow, false) guiSetVisible(GUIEditor.window[1], false) end ) -- -- Assigns the player the job and hides the job window. -- function onJobAccepted() local jobName = guiGetText(GUIEditor.label[1]) if jobName then triggerServerEvent("playerJoinJob", root, jobName) hideJobWindow() end end -- -- Displays the GTC Employment window with the given job information. function showJobWindow(jobName) if jobName then guiSetVisible(GUIEditor.window[1], true) triggerEvent("onWindowOpen", localPlayer) -- Display the jobs name. guiSetText(GUIEditor.label[1], jobName) -- Load and display the jobs memo. local memoText = "" local memoConfig = xmlLoadFile("jobmemos.xml") if memoConfig then local jobMemos = xmlNodeGetChildren(memoConfig) for i,node in ipairs(jobMemos) do if (xmlNodeGetAttribute(node, "jobName") == jobName) then memoText = xmlNodeGetValue(node) break end end if (memoText == "") then memoText = "..jobName.."'>" end xmlUnloadFile(memoConfig) else memoText = "" end guiSetText(GUIEditor.memo[1], memoText) end end -- -- Hides the GTC Employment window from view. -- function hideJobWindow() guiSetVisible(GUIEditor.window[1], false) triggerEvent("onWindowClose", localPlayer) end -- -- Bring up the job window if a player walks into a job marker. -- addEventHandler("onClientMarkerHit", root, function (hitPlayer, dimensionMatch) -- If the player isn't flying... if not getElementData(hitPlayer, "superman:flying") then -- If the player isn't too far above the marker... local px,py,px = getElementPosition(hitPlayer) local mx,my,mz = getElementPosition(source) if (px <= (mz + 5)) then local markType = getElementData(source, "markType") if (markType == "jobnpc") and (getPedOccupiedVehicle(hitPlayer) == false) then local jobName = getElementData(source, "jobName") local playerJob = getTeamName(getPlayerTeam(hitPlayer)) -- If the player doesn't already have this job, show the job window. if (playerJob ~= jobName) then showJobWindow(jobName) end end end end end )
  5. Okay, I discovered the 'debugscript' command and found out the problems. Which there were alot of. Small ones. So I can't really explain what I did wrong but I'm posting the corrected code here for anybody who might benefit from it. [EDIT] Mr.gSub I started to think that at first about the marker collision but I had already tested it before creating the GUI and it worked fine. As for the other changes, my script works now, but doesn't hurt to add those changes. Accounted for in the below code. And thanks for replying. vspawnsys_c.lua [Client] --[[ vspawnsys_c.lua - Manages the GUI for the vehicle spawning system. --]] -- Defines what vehicles can be spawned by different vspawn types. VSPAWN_TYPES = { ["hospital"] = { 534, -- Remington 581, -- BF-400 457 -- Caddy } } GUIEditor = { gridlist = {}, window = {}, button = {} } -- -- Creates the vehicle spawn menu and hides it for later. -- addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(510, 466, 255, 250, "GTC Vehicles", false) guiWindowSetSizable(GUIEditor.window[1], false) GUIEditor.gridlist[1] = guiCreateGridList(14, 31, 227, 173, false, GUIEditor.window[1]) guiGridListAddColumn(GUIEditor.gridlist[1], "Key", 0.15) guiGridListAddColumn(GUIEditor.gridlist[1], "Vehicle Name", 0.85) GUIEditor.button[1] = guiCreateButton(63, 214, 128, 26, "Spawn Vehicle", false, GUIEditor.window[1]) addEventHandler("onClientGUIClick", GUIEditor.button[1], onVehicleSelected, false) guiSetVisible(GUIEditor.window[1], false) end ) -- -- Spawns the currently selected vehicle. -- function onVehicleSelected() local vspawnMark = getElementData(localPlayer, "vspawnMark") if vspawnMark then local selection = guiGridListGetSelectedItem(GUIEditor.gridlist[1]) if (selection == -1) then selection = 1 end local validCars = VSPAWN_TYPES[getElementData(vspawnMark, "vspawnType")] if validCars then local x,y,z = getElementPosition(vspawnMark) triggerServerEvent("vspawnCreateVehicle", root, validCars[selection], x,y,z, getElementData(vspawnMark, "rotZ")) end end hideSpawnerWindow() end -- -- Pulls up the vspawn selection window, loading the vehicles from the given vspawn type. -- function showSpawnerWindow(spawnerType) guiSetVisible(GUIEditor.window[1], true) local validCars = VSPAWN_TYPES["hospital"] if validCars then -- Add all valid cars for the spawner type to the grid list. for i = 1, #validCars do local row = guiGridListAddRow(GUIEditor.gridlist[1]) guiGridListSetItemText(GUIEditor.gridlist[1], row, 1, tostring(i), false, true) -- Key guiGridListSetItemText(GUIEditor.gridlist[1], row, 2, getVehicleNameFromModel(validCars[i]), false, false) -- Vehicle Name end end end -- -- Hides the vspawn selection window and removes all grid list entries. -- function hideSpawnerWindow() guiGridListClear(GUIEditor.gridlist[1]) guiSetVisible(GUIEditor.window[1], false) showCursor(false) guiSetInputEnabled(false) end -- -- Bring up the v-spawner GUI when a player enters a spawn marker. -- addEventHandler("onClientMarkerHit", root, function (hitPlayer, dimensionMatch) -- If the player walks into a vehicle spawner if (getElementData(source, "markType") == "vspawner") then -- Make sure this is the first moment he's walked into the marker. if (getElementData(hitPlayer, "vspawnEntered") ~= true) then -- If isn't in a car, bring up the spawner menu. if (getPedOccupiedVehicle(hitPlayer) == false) then setElementData(hitPlayer, "vspawnEntered", true) setElementData(hitPlayer, "vspawnMark", source) -- Save the current spawn marker for use in 'onVehicleSelect()' showSpawnerWindow(getElementData(source, "vspawnType")) end end end end ) -- -- Reset the "vspawnEntered" player data when a vspawner marker has been left. -- addEventHandler("onClientMarkerLeave", root, function (leftPlayer, dimensionMatch) if dimensionMatch and (getElementData(source, "markType") == "vspawner") then setElementData(leftPlayer, "vspawnEntered", false) setElementData(leftPlayer, "vspawnMark", false) hideSpawnerWindow() end end ) vspawnsys_s.lua [server] --[[ vspawnsys_s.lua - Manages the serverside vehicle spawning logic. --]] addEvent("vspawnCreateVehicle", true) -- -- Spawns a player into the given vehicle at his position. -- function vspawnCreateVehicle(vehID, x,y,z, rot) if isElement(client) and vehID then -- Check if the user already has a spawned vehicle, if so, unspawn it. local vspawnSlot = getElementData(client, "vspawnSlot") if (vspawnSlot ~= false) then destroyElement(vspawnSlot) end -- Create the vehicle and spawn the player inside of it. local veh = createVehicle(vehID, x,y,z + 1.5, 0,0,360 - rot) setVehicleDamageProof(veh, false) setVehicleFuelTankExplodable(veh, false) warpPedIntoVehicle(client, veh) -- Add the car to the players vspawn slot (players can have only 1 vspawn car). setElementData(client, "vspawnSlot", veh) end end addEventHandler("vspawnCreateVehicle", root, vspawnCreateVehicle)
  6. I've been working on a car spawning system, and everything in my script worked when I had it to where, if you walk into the spawn marker, it simply spawns 1 type of car with no GUI. Then, I created a GUI with the 'guieditor' resource, and fit it into my clientside script. From what I'm seeing, everything should work fine. Also, I don't get any errors or warnings whatsoever. But no matter what I've tried I can't seem to get my GUI to show, what could be causing this? Before I show you the main scripts, I figure for completeness' sake I'll show you the EDF that defines the spawner markers and the map code for the spawners, along with the code that generated the markers. EDF: <edf name="GTC"> <element name="spawnpoint" friendlyname="Spawnpoint" icon="edf/spawnpoint.png"> <data name="position" type="coord3d" default="0,0,0" /> <data name="rotation" type="coord3d" default="0,0,0" /> <ped model="292" rotation="!rotation!" /> <blip position="!position!" icon="22" size="2" color="#ff0000ff" dimension="0" /> </element> <element name="vspawner" friendlyname="Car Spawner" icon="edf/vehicle.png"> <data name="position" type="coord3d" default="0,0,0" /> <data name="rotation" type="coord3d" default="0,0,0" /> <data name="color" type="color" default="#ffffffff" /> <data name="vspawnType" type="string" default="hospital" /> <marker size="2" type="cylinder" color="!color!" /> </element> </edf> The spawner line in the map file: <vspawner id="vspawner (1)" color="#A3A3A3AD" vspawnType="hospital" posX="2041" posY="-1429.4" posZ="16.1" rotX="0" rotY="0" rotZ="270"></vspawner> Code that generates the markers from the map data: local vspawners = getElementsByType("vspawner", MAP_ROOT) -- Create the vehicle spawner blips. for k,v in pairs(vspawners) do local x = getElementData(v, "posX") local y = getElementData(v, "posY") local z = getElementData(v, "posZ") local clr = getElementData(v, "color") local r,g,b,a = hexToRgb(clr) local spawnMark = createMarker(x,y,z, "cylinder", 2.0, r,g,b,a) setElementData(spawnMark, "markType", "vspawner") setElementData(spawnMark, "vspawnType", getElementData(v, "vspawnType")) setElementData(spawnMark, "rotZ", getElementData(v, "rotZ")) end Okay, now for the main script files. vspawnsys_c.lua VSPAWN_TYPES = { ["hospital"] = { 534, -- Remington 581, -- BF-400 457 -- Caddy } } GUIEditor = { gridlist = {}, window = {}, button = {} } -- -- Creates the vehicle spawner interface. -- addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(510, 466, 255, 250, "GTC Vehicles", false) guiWindowSetSizable(GUIEditor.window[1], false) GUIEditor.gridlist[1] = guiCreateGridList(14, 31, 227, 173, false, GUIEditor.window[1]) guiGridListAddColumn(GUIEditor.gridlist[1], "Key", 0.5) guiGridListAddColumn(GUIEditor.gridlist[1], "Vehicle Name", 0.5) GUIEditor.button[1] = guiCreateButton(63, 214, 128, 26, "Spawn Vehicle", false, GUIEditor.window[1]) addEventHandler("onClientGUIClick", GUIEditor.button[1], onVehicleSelected, false) guiSetVisible(GUIEditor.window[1], false) end ) -- -- Spawns the currently selected vehicle. -- function onVehicleSelected() local vspawnMark = getElementData(localPlayer, "vspawnMark") if vspawnMark then local selection = guiGridListSetSelectedItem(GUIEditor.gridlist[1]) if not selection then selection = 1 end local validCars = VSPAWN_TYPES[getElementData(vspawnMark, "vspawnType")] if validCars then local x,y,z = getElementPosition(vspawnMark) triggerServerEvent("vspawnCreateVehicle", root, validCars[selection], x,y,z, getElementData(vspawnMark, "rotZ")) end end hideSpawnerWindow() end -- -- Pulls up the vspawn selection window, loading the vehicles from the given vspawn type. -- function showSpawnerWindow(spawnerType) if (GUIEditor.window[1] ~= nil) then guiSetVisible(GUIEditor.window[1], true) else outputChatBox("An unexpected error has occurred and the spawn menu has not been created.") end showCursor(true) guiSetInputEnabled(true) local validCars = VSPAWN_TYPES[spawnerType] if validCars then -- Add all valid cars for the spawner type to the grid list. for i = 1, #validCars do local row = guiGridListAddRow(GUIEditor.gridlist[1]) guiGridListSetItemText(GUIEditor.gridlist[1], row, 1, tostring(i), false, true) -- Key guiGridListSetItemText(GUIEditor.gridlist[1], row, 2, getVehicleName(validCars[i]), false, false) -- Vehicle Name end end end -- -- Hides the vspawn selection window and removes all grid list entries. -- function hideSpawnerWindow() guiGridListClear(GUIEditor.gridlist[1]) guiSetVisible(GUI_vehicleListWnd, false) showCursor(false) guiSetInputEnabled(false) end -- -- Bring up the v-spawner GUI when a player enters a spawn marker. -- addEventHandler("onClientMarkerHit", root, function (hitPlayer, dimensionMatch) -- If the player walks into a vehicle spawner if dimensionMatch and (getElementData(source, "markType") == "vspawner") then -- Make sure this is the first moment he's walked into the marker. if (getElementData(hitPlayer, "vspawnEntered") ~= true) then -- If isn't in a car, bring up the spawner menu. if (getPedOccupiedVehicle(hitPlayer) == false) then setElementData(hitPlayer, "vspawnEntered", true) setElementData(hitPlayer, "vspawnMark", source) -- Save the current spawn marker for use in 'onVehicleSelect()' showSpawnerWindow(getElementData(source, "vspawnType")) end end end end ) -- -- Reset the "vspawnEntered" player data when a vspawner marker has been left. -- addEventHandler("onClientMarkerLeave", root, function (leftPlayer, dimensionMatch) if dimensionMatch and (getElementData(source, "markType") == "vspawner") then setElementData(leftPlayer, "vspawnEntered", false) setElementData(hitPlayer, "vspawnMark", false) if (guiGetVisible(GUIEditor.window[1]) == true) hideSpawnerWindow() end end end ) And the serverside... vspawnsys_s.lua addEvent("vspawnCreateVehicle", true) -- -- Spawns a player into the given vehicle at his position. -- function vspawnCreateVehicle(vehID, x,y,z, rot) if isElement(client) and vehID then -- Check if the user already has a spawned vehicle, if so, unspawn it. local vspawnSlot = getElementData(client, "vspawnSlot") if (vspawnSlot ~= false) then destroyElement(vspawnSlot) end -- Create the vehicle and spawn the player inside of it. local veh = createVehicle(412, x,y,z + 1.5, 0,0,360 - rot) setVehicleDamageProof(veh, false) setVehicleFuelTankExplodable(veh, false) warpPedIntoVehicle(client, veh) -- Add the car to the players vspawn slot (players can have only 1 vspawn car). setElementData(client, "vspawnSlot", veh) end end addEventHandler("vspawnCreateVehicle", root, vspawnCreateVehicle) I'm sure it's some simple mistake I'm overlooking, but after almost an hour just trying to figure out how to get a window to show, I want to figure this out so I can finally move on.
  7. I wrote a spawn-protection script, it makes the player partially transparent so players know they're under spawn-protection. It also makes them unable to use weapons until they are no longer under spawn-protection, but it's missing one thing. I need to make it so that when a player is under spawn protection, there is no collision-detection when they intersect with another player. When two players spawn at the same hospital at once, they get stuck in each other, how can I prevent this? I've seen other servers that allow you move right out of players who are standing on the spawnpoint. I saw an event named 'onPlayerContact', it might be useful but I don't know how to continue from there. Would I handle this event, check if the 'currentElement' argument is another player, check if one of the players is spawn-protected and if so, cancel the event? Here is what I'm working with: hospitals_s.lua [server-Side] ... -- Spawns the player at the nearest hospital. function spawnAtHospital(thePlayer) -- Spawn-protect the player for 8 seconds. startSpawnProtection(thePlayer) -- Spawn at the nearest hospital. local xx,yy,zz,rr = findNearestHostpital(thePlayer) spawnPlayer(thePlayer, xx,yy,zz,rr) fadeCamera(thePlayer, true, 3.0) end -- Spawn-protect the player for 8 seconds. function startSpawnProtection(thePlayer) -- Spawn-protect the player for 8 seconds. setElementData(thePlayer, "spawnProtected", true) setElementAlpha(thePlayer, 150) setTimer( function() setElementData(thePlayer, "spawnProtected", false) setElementAlpha(thePlayer, 255) -- Load weapon and skin data. if (SAVE_DATA[thePlayer]) then setElementModel(thePlayer, SAVE_DATA[thePlayer].skin) if SAVE_DATA[thePlayer].weapons then for weapon, ammo in pairs (SAVE_DATA[thePlayer].weapons) do giveWeapon(thePlayer, weapon, ammo, true) end end end end, 8000, 1 ) end hospitals_c.lua [Client-Side] function onClientPlayerDamage(attacker, weapon, bodypart) if (getElementData(localPlayer, "spawnProtected") == true) then cancelEvent() end end addEventHandler("onClientPlayerDamage", localPlayer, onClientPlayerDamage)
  8. Thank you IIYAMA, it's working perfect. Here's the code for anybody who does some searching on how to do this. glue_c.lua [Client] -- Move backwards through the weapon slots. function prevWeapon() local wep = nil local slot = getPedWeaponSlot(localPlayer) local slotHasWep = false -- Keep looking backwards for a slot that contains a weapon. while (slotHasWep == false) do -- Keep 'slot' in the range of 0-12 and decrement it. if (slot == 0) then slot = 12 else slot = slot - 1 end if (slot == 0) then -- Allow the player to select fists. slotHasWep = true break else -- Check if there is a weapon and if it has any ammo. wep = getPedWeapon(localPlayer, slot) slotHasWep = ((wep ~= 0) and (getPedTotalAmmo(localPlayer, slot) ~= 0)) if (slotHasWep) then break end end end setPedWeaponSlot(localPlayer, slot) end -- Move forward through the weapon slots. function nextWeapon() local wep = nil local slot = getPedWeaponSlot(localPlayer) local slotHasWep = false -- Keep looking forwards for a slot that contains a weapon. while (slotHasWep == false) do -- Keep 'slot' in the range of 0-12 and increment it. if (slot == 12) then slot = 0 else slot = slot + 1 end if (slot == 0) then -- Allow the player to select fists. slotHasWep = true break else -- Check if there is a weapon and if it has any ammo. wep = getPedWeapon(localPlayer, slot) slotHasWep = ((wep ~= 0) and (getPedTotalAmmo(localPlayer, slot) ~= 0)) if (slotHasWep) then break end end end setPedWeaponSlot(localPlayer, slot) end -- Glue the player to the vehicle. function glue() if not getPedOccupiedVehicle(localPlayer) then local vehicle = getPedContactElement(localPlayer) if getElementType(vehicle) == "vehicle" then local px, py, pz = getElementPosition(localPlayer) local vx, vy, vz = getElementPosition(vehicle) local sx = px - vx local sy = py - vy local sz = pz - vz local rotpX = 0 local rotpY = 0 local rotpZ = getPedRotation(localPlayer) local rotvX,rotvY,rotvZ = getElementRotation(vehicle) local t = math.rad(rotvX) local p = math.rad(rotvY) local f = math.rad(rotvZ) local ct = math.cos(t) local st = math.sin(t) local cp = math.cos(p) local sp = math.sin(p) local cf = math.cos(f) local sf = math.sin(f) local z = ct*cp*sz + (sf*st*cp + cf*sp)*sx + (-cf*st*cp + sf*sp)*sy local x = -ct*sp*sz + (-sf*st*sp + cf*cp)*sx + (cf*st*sp + sf*cp)*sy local y = st*sz - sf*ct*sx + cf*ct*sy local rotX = rotpX - rotvX local rotY = rotpY - rotvY local rotZ = rotpZ - rotvZ local slot = getPedWeaponSlot(localPlayer) triggerServerEvent("gluePlayer", localPlayer, slot, vehicle, x, y, z, rotX, rotY, rotZ) unbindKey("x", "down", glue) bindKey("x", "down", unglue) bindKey("jump", "down", unglue) bindKey("q", "down", prevWeapon) bindKey("e", "down", nextWeapon) end end end -- Unglue the player from the vehicle function unglue() triggerServerEvent("ungluePlayer", localPlayer) unbindKey("jump", "down", unglue) unbindKey("x", "down", unglue) bindKey("x", "down", glue) unbindKey("q", "down", prevWeapon) unbindKey("e", "down", nextWeapon) end addCommandHandler("glue", glue) addCommandHandler("unglue", unglue) bindKey("x", "down", glue) glue_s.lua [server] function gluePlayer(slot, vehicle, x, y, z, rotX, rotY, rotZ) attachElements(source, vehicle, x, y, z, rotX, rotY, rotZ) setPedWeaponSlot(source, slot) end function ungluePlayer() detachElements(source) end addEvent("gluePlayer",true) addEvent("ungluePlayer",true) addEventHandler("gluePlayer", getRootElement(), gluePlayer) addEventHandler("ungluePlayer", getRootElement(), ungluePlayer)
  9. So instead of just moving to the next slot, I need to check for the next slot that actually contains a weapon, and then set that slot? How can I check if a weapon slot actually contains a weapon? I looked through the ped functions in the wiki and I can only find a get and set method for the slot, I haven't found a function that can check the contents of a particular slot.
  10. Since weapon switching can't be done while glued to a vehicle, I tried to modify a glue script made by uPrell. I made 2 functions to change weapons that are bound to Q and E just as X is bound to 'glue'. Somewhere online I read I could still set the players weapon slot so I thought it would work. Either I made a simple mistake in the code or I'm going about this wrong. Did plenty searching and couldn't find anything that could help. Here is the modified script, if you could tell me what I'm doing wrong or how I could do this it'd be greatly appreciated. glue.lua [Client] (This is the only file I modified) -- Move backwards through the weapon slots. function prevWeapon() local player = getLocalPlayer() local slot = getPedWeaponSlot(player) if (slot == 0) then slot = 12 else slot = slot - 1 end setPedWeaponSlot(player, slot) end -- Move forward through the weapon slots. function nextWeapon() local player = getLocalPlayer() local slot = getPedWeaponSlot(player) if (slot == 12) then slot = 0 else slot = slot + 1 end setPedWeaponSlot(player, slot) end -- Glue the player to the vehicle. function glue() local player = getLocalPlayer() if not getPedOccupiedVehicle(player) then local vehicle = getPedContactElement(player) if getElementType(vehicle) == "vehicle" then local px, py, pz = getElementPosition(player) local vx, vy, vz = getElementPosition(vehicle) local sx = px - vx local sy = py - vy local sz = pz - vz local rotpX = 0 local rotpY = 0 local rotpZ = getPedRotation(player) local rotvX,rotvY,rotvZ = getElementRotation(vehicle) local t = math.rad(rotvX) local p = math.rad(rotvY) local f = math.rad(rotvZ) local ct = math.cos(t) local st = math.sin(t) local cp = math.cos(p) local sp = math.sin(p) local cf = math.cos(f) local sf = math.sin(f) local z = ct*cp*sz + (sf*st*cp + cf*sp)*sx + (-cf*st*cp + sf*sp)*sy local x = -ct*sp*sz + (-sf*st*sp + cf*cp)*sx + (cf*st*sp + sf*cp)*sy local y = st*sz - sf*ct*sx + cf*ct*sy local rotX = rotpX - rotvX local rotY = rotpY - rotvY local rotZ = rotpZ - rotvZ local slot = getPedWeaponSlot(player) --outputDebugString("gluing ".. getPlayerName(player) .." to " .. getVehicleName(vehicle) .. "(offset: "..tostring(x)..","..tostring(y)..","..tostring(z).."; rotation:"..tostring(rotX)..","..tostring(rotY)..","..tostring(rotZ)..")") triggerServerEvent("gluePlayer", player, slot, vehicle, x, y, z, rotX, rotY, rotZ) unbindKey("x","down",glue) bindKey("x","down",unglue) bindKey("jump","down",unglue) bindKey("q", "down", prevWeapon) bindKey("e", "down", nextWeapon) end end end -- Unglue the player from the vehicle function unglue() local player = getLocalPlayer() triggerServerEvent("ungluePlayer", player) unbindKey("jump","down",unglue) unbindKey("x","down",unglue) bindKey("x","down",glue) unbindKey("q", "down", prevWeapon) unbindKey("e", "down", nextWeapon) end addCommandHandler("glue", glue) addCommandHandler("unglue", unglue) bindKey("x","down",glue) glueS.lua [server] function gluePlayer(slot, vehicle, x, y, z, rotX, rotY, rotZ) attachElements(source, vehicle, x, y, z, rotX, rotY, rotZ) setPedWeaponSlot(source, slot) end function ungluePlayer() detachElements(source) end addEvent("gluePlayer",true) addEvent("ungluePlayer",true) addEventHandler("gluePlayer", getRootElement(), gluePlayer) addEventHandler("ungluePlayer", getRootElement(), ungluePlayer) The code doesn't throw any warnings or errors, but it doesn't do anything. Thanks in advance for any help you can give.
  11. Thank You! That worked perfectly
  12. I just tried what you said, and even with the command rights defined in the ACL to only allow admins access, it still allows everyone to use the command.
  13. Ahh, wow it's in big red letters in the wiki, idk how I missed that or what I was thinking. Thank you! Well, the check for admin access doesn't work, with it in place the script doesn't work at all, it doesn't turn on car flight when 'Admin' or notify of denied access when 'Default'. Am I doing the check wrong? Also, is there a strict separation of client-side and server-side scripts? Can I have both client-side and server-side functions in the same script? I notice the resource separated it in 2 scripts, client and server.
  14. I downloaded and adapted to my needs a free resource made by lLinux that enables cars to fly by using the 'setWorldSpecialPropertyEnabled' function. Is there anyway that I can let each admin use the '/carsfly' command to toggle their cars ability to fly? I realize the 'setWorldSpecialPropertyEnabled' sets that ability for every user on the server. I just started learning to create a server the other day, the syntax of Lua was easy to figure out, but I don't know the API very well. First, I tried to put the car-flight resource in the "Admin" group in the ACL, then I tried defining the rights for the Access groups, 'false' for anything other than the "Admin" group. It still let normal players use the command. I also tried doing a check in the Lua script but I'm pretty sure I went about it all wrong. Is it possible to allow each individual admin to decide if they want their cars to fly? Here's the scripts: c_fly.lua --[[ .:Fly:. By lLinux --INFORMATION-- The code of this resource is free, you can use it and edit when you want it. --Instructions-- 1. Put the resource in the resources folder. 2. Start the resource 3. Use the command: /fly ]]-- carsCanFly = false function toggleCarFlight() local accName = getAccountName(getPlayerAccount(source)) if isObjectInACLGroup("user."..accName, aclGetGroup("Admin")) then -- Never evaluates to 'true' when 'Admin' if (carsCanFly == false) then carsCanFly = true setWorldSpecialPropertyEnabled("aircars", true) triggerServerEvent("carFlightOn", getLocalPlayer()) else carsCanFly = false setWorldSpecialPropertyEnabled("aircars", false) triggerServerEvent("carFlightOff", getLocalPlayer()) end else outputChatBox("#ffff00Dude, only admins can do that.", source, 255, 255, 255) -- Never gets displayed when 'Default' end end addCommandHandler("carsfly", toggleCarFlight) s_fly.lua --[[ .:Fly:. By lLinux --INFORMATION-- The code of this resource is free, you can use it and edit when you want it. --Instructions-- 1. Put the resource in the resources folder. 2. Start the resource 3. Use the command: /fly ]]-- function enableCarFlight() outputChatBox("#ffff00Car flight is now enabled.", source, 255, 255, 255, true) end addEvent("carFlightOn", true) addEventHandler("carFlightOn", getRootElement(), enableCarFlight) function disableCarFlight(thePlayer) outputChatBox("#ffff00Car flight is now disabled.", source, 255, 255, 255, true) end addEvent("carFlightOff", true) addEventHandler("carFlightOff", getRootElement(), disableCarFlight) Also, if you knew any resources that allows players to fly while on foot, or if you could help me a little bit on creating the script myself, that'd be awesome. Thanks in advance.
×
×
  • Create New...