3eBpA Posted February 13, 2014 Share Posted February 13, 2014 Hello guys, I have got a question, how can I use a server script variables or functions to client script, for example, teams, I've got teams on my server and I need to use them on client, how can I do that ? =\ Link to comment
Bonsai Posted February 13, 2014 Share Posted February 13, 2014 You need to use get functions, such as getTeamFromName etc. Link to comment
Moderators Citizen Posted February 13, 2014 Moderators Share Posted February 13, 2014 For teams, you can use the internal team system from MTA (as Bonsai suggested) because they are synced on both sides. But more generally, if you want to send a copy of a variable to the other side, you will have to use: triggerClientEvent --to send to the client triggerServerEvent --to send to the server You also can use this trick: You can use setElementData(resourceRoot, "myData", myValue) The element datas are synced between both sides. You can get the value of "myData" by doing: getElementData(resourceRoot, "myData") Regards, Citizen Link to comment
3eBpA Posted February 13, 2014 Author Share Posted February 13, 2014 well, why my code doesn't work then ? : O function Stun(attacker) if getPlayerTeam(attacker) == police and getPlayerTeam(source) ~= police and getElementModel(attacker) == 3 setElementFrozen(source) end end addEventHandler("OnClientWeaponFire", getRootElement(), Stun) it should stun guy with weaponID 3 if his team != police but it doesn't works, maybe because team creation is written in server.lua ? Link to comment
Bonsai Posted February 13, 2014 Share Posted February 13, 2014 Did you even read what we wrote? if the team is stored in the police variable server side, then the client script doesn't know about the police variable. So you you have to do what Citizen or I told you to. Link to comment
Moderators Citizen Posted February 13, 2014 Moderators Share Posted February 13, 2014 it's "onClientWeaponFire" not "OnClientWeaponFire". Tip: - To debug this problem, you could add an outputChatBox like this: function Stun(attacker) outputChatBox("Fire !") if getPlayerTeam(attacker) == police and getPlayerTeam(source) ~= police and getElementModel(attacker) == 3 setElementFrozen(source) end end addEventHandler("OnClientWeaponFire", getRootElement(), Stun) And you would know the problem wasn't from the team functions but the event. Regards, Citizen Link to comment
3eBpA Posted February 13, 2014 Author Share Posted February 13, 2014 it's "onClientWeaponFire" not "OnClientWeaponFire".Tip: - To debug this problem, you could add an outputChatBox like this: function Stun(attacker) outputChatBox("Fire !") if getPlayerTeam(attacker) == police and getPlayerTeam(source) ~= police and getElementModel(attacker) == 3 setElementFrozen(source) end end addEventHandler("OnClientWeaponFire", getRootElement(), Stun) And you would know the problem wasn't from the team functions but the event. Regards, Citizen I've changed OnClientWeaponFire to onClientWeaponFire, I think the problem is in teams =\ Link to comment
.:HyPeX:. Posted February 13, 2014 Share Posted February 13, 2014 Normaly, you shold do this: police = getTeamFromName("Police - Team - Name - Here") After that, if the team exists, it should work. Link to comment
3eBpA Posted February 13, 2014 Author Share Posted February 13, 2014 Normaly, you shold do this: police = getTeamFromName("Police - Team - Name - Here") After that, if the team exists, it should work. thank you man, your really save me from sleepless nights Link to comment
Moderators Citizen Posted February 13, 2014 Moderators Share Posted February 13, 2014 Wait, does this work ?! The wiki says the event isn't triggered with melee weapons, and 3 is a melee weapon so it shouldn't work . See the note of the wiki page: Note: This event is only for custom weapons that were created with createWeapon, for player held weapons use onClientPlayerWeaponFire. So use onClientPlayerWeaponFire event instead. But, there is another important note: This does not trigger for projectiles based, or melee weapons and you are using the weaponID 3 so according to this list: Weapon ids list it is a melee weapon, so it won't work. So what can we do now ?? We can try to find another event, and I found this event: onClientPlayerDamage This event is triggered whenever a player is damaged. and it gives us an important parameter: attacker: A player element representing the attacker Great ! We can do it with this event: function Stun( attacker ) outputChatBox("Took damage !") local policeTeam = getTeamFromName("police") if getPlayerTeam(attacker) == policeTeam and getPlayerTeam(source) ~= policeTeam and getElementModel(attacker) == 3 then outputChatbox("Frozen !") setElementFrozen(source, true) end end addEventHandler("onClientPlayerDamage", localPlayer, Stun) Tell me if it works. Regards, Citizen Link to comment
3eBpA Posted February 13, 2014 Author Share Posted February 13, 2014 Wait, does this work ?! The wiki says the event isn't triggered with melee weapons, and 3 is a melee weapon so it shouldn't work .See the note of the wiki page: Note: This event is only for custom weapons that were created with createWeapon, for player held weapons use onClientPlayerWeaponFire. So use onClientPlayerWeaponFire event instead. But, there is another important note: This does not trigger for projectiles based, or melee weapons and you are using the weaponID 3 so according to this list: Weapon ids list it is a melee weapon, so it won't work. So what can we do now ?? We can try to find another event, and I found this event: onClientPlayerDamage This event is triggered whenever a player is damaged. and it gives us an important parameter: attacker: A player element representing the attacker Great ! We can do it with this event: function Stun( attacker ) outputChatBox("Took damage !") local policeTeam = getTeamFromName("police") if getPlayerTeam(attacker) == policeTeam and getPlayerTeam(source) ~= policeTeam and getElementModel(attacker) == 3 then outputChatbox("Frozen !") setElementFrozen(source, true) end end addEventHandler("onClientPlayerDamage", localPlayer, Stun) Tell me if it works. Regards, Citizen thanks, I'm gonna try this tomorrow Link to comment
Bonsai Posted February 13, 2014 Share Posted February 13, 2014 Normaly, you shold do this: police = getTeamFromName("Police - Team - Name - Here") After that, if the team exists, it should work. thank you man, your really save me from sleepless nights Told you that hours ago. If you would pay more attention to replies you could have saved us from trying to fix a problem that is already fixed. Link to comment
3eBpA Posted February 15, 2014 Author Share Posted February 15, 2014 Wait, does this work ?! The wiki says the event isn't triggered with melee weapons, and 3 is a melee weapon so it shouldn't work .See the note of the wiki page: Note: This event is only for custom weapons that were created with createWeapon, for player held weapons use onClientPlayerWeaponFire. So use onClientPlayerWeaponFire event instead. But, there is another important note: This does not trigger for projectiles based, or melee weapons and you are using the weaponID 3 so according to this list: Weapon ids list it is a melee weapon, so it won't work. So what can we do now ?? We can try to find another event, and I found this event: onClientPlayerDamage This event is triggered whenever a player is damaged. and it gives us an important parameter: attacker: A player element representing the attacker Great ! We can do it with this event: function Stun( attacker ) outputChatBox("Took damage !") local policeTeam = getTeamFromName("police") if getPlayerTeam(attacker) == policeTeam and getPlayerTeam(source) ~= policeTeam and getElementModel(attacker) == 3 then outputChatbox("Frozen !") setElementFrozen(source, true) end end addEventHandler("onClientPlayerDamage", localPlayer, Stun) Tell me if it works. Regards, Citizen yep, works, thanks man Link to comment
Moderators Citizen Posted February 15, 2014 Moderators Share Posted February 15, 2014 You're welcome 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