Emanuel Posted April 22, 2014 Posted April 22, 2014 First of all, I am a beginner in this gigantic world, and sorry for my ignorance. I have some bugs, that I want to be solved. Bugs: - The project is not synchronized. Each player gets attacked by his own turret, and not from the one I have created. - When I use the command /turret it creates one on me, and other players have one on their head. For example, if anyone uses /turret, I will have a turret on me, which doesn't make sence. Here is the project : Client : function turret() x, y, z = getElementPosition(getLocalPlayer()) weapon = createWeapon("m4", x, y, z+1.5) setWeaponClipAmmo ( weapon,99999) setWeaponState ( weapon,"firing") setWeaponTarget ( weapon, true ) setWeaponTarget ( weapon ,getLocalPlayer(), 255 ) end addEvent("turret", true) addEventHandler("turret", root, turret) function destroy() destroyElement (weapon) end addEvent("destroy", true) addEventHandler("destroy", root, destroy) Server : function turret() triggerClientEvent(root, "turret", root, x, y, z) end addCommandHandler("turret", turret) function destroy() triggerClientEvent(root, "destroy", root, x, y, z) end addCommandHandler("end", destroy) Meta : <meta> <script src="client.lua" type="client" /> <script src="server.lua" type="server" /> <min_mta_version client="1.3.0-9.04555"></min_mta_version> </meta> I would appreciate if you could fix it. thanks.
WASSIm. Posted April 22, 2014 Posted April 22, 2014 you can create weapon with same command but problem if player joined server after create weapon will don't see him --> Client local weapons = { } function turret(thePlayer) if not (weapon[thePlayer]) then local x, y, z = getElementPosition(thePlayer) weapon[thePlayer] = createWeapon("m4", x, y, z) setWeaponState(weapon[thePlayer],"firing") attachElements(weapon[thePlayer], thePlayer, 0, 0, 1.5) else destroyElement (weapon[thePlayer]) weapon[thePlayer] = nil end end addEvent("turret", true) addEventHandler("turret", root, turret) --> Server function turret(thePlayer) triggerClientEvent(root, "turret", thePlayer) end addCommandHandler("turret", turret)
Ab-47 Posted April 22, 2014 Posted April 22, 2014 Use a loop to get the all the players to fire at, then add a check to see if the player isn't yourself and I think you'll be fine. You're using getLocalPlayer(), which gets the player who triggered the function, so yea, it's obviously gonna shoot at you
Einheit-101 Posted April 22, 2014 Posted April 22, 2014 Those weapon functions are currently almost useless because they are not synced. They are currently working on it.
Emanuel Posted April 22, 2014 Author Posted April 22, 2014 you can create weapon with same command but problem if player joined server after create weapon will don't see him --> Client local weapons = { } function turret(thePlayer) if not (weapon[thePlayer]) then local x, y, z = getElementPosition(thePlayer) weapon[thePlayer] = createWeapon("m4", x, y, z) setWeaponState(weapon[thePlayer],"firing") attachElements(weapon[thePlayer], thePlayer, 0, 0, 1.5) else destroyElement (weapon[thePlayer]) weapon[thePlayer] = nil end end addEvent("turret", true) addEventHandler("turret", root, turret) --> Server function turret(thePlayer) triggerClientEvent(root, "turret", thePlayer) end addCommandHandler("turret", turret) This isn't working Use a loop to get the all the players to fire at, then add a check to see if the player isn't yourself and I think you'll be fine.You're using getLocalPlayer(), which gets the player who triggered the function, so yea, it's obviously gonna shoot at you Do you even know how noob I am in this ? lol .I really need help in this PS : Someone said that I could use triggerServerEvent("eventName", root, theResultOfFunction) Any suggestion ?
Emanuel Posted April 22, 2014 Author Posted April 22, 2014 you can create weapon with same command but problem if player joined server after create weapon will don't see him --> Client local weapons = { } function turret(thePlayer) if not (weapon[thePlayer]) then local x, y, z = getElementPosition(thePlayer) weapon[thePlayer] = createWeapon("m4", x, y, z) setWeaponState(weapon[thePlayer],"firing") attachElements(weapon[thePlayer], thePlayer, 0, 0, 1.5) else destroyElement (weapon[thePlayer]) weapon[thePlayer] = nil end end addEvent("turret", true) addEventHandler("turret", root, turret) --> Server function turret(thePlayer) triggerClientEvent(root, "turret", thePlayer) end addCommandHandler("turret", turret) This isn't working Use a loop to get the all the players to fire at, then add a check to see if the player isn't yourself and I think you'll be fine.You're using getLocalPlayer(), which gets the player who triggered the function, so yea, it's obviously gonna shoot at you Do you even know how noob I am in this ? lol .I really need help in this PS : Someone said that I could use triggerServerEvent("eventName", root, theResultOfFunction) Any suggestion ? NOTE : It is something like this. It is set on a determinated position, not attacked to a player, or a car.
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