Jump to content

export problem


Recommended Posts

Posted

Hello, its me again :/

I was trying to understand exports so I tried to make a script to understand how it works but I failed.

I was trying to apply this tutorial https://forum.multitheftauto.com/viewtopic.php?f=148&t=46167 .

So can someone tell me what is wrong with my script?

Server sided scrit:

  
-- 
-- Virus Script -Server Sided 
-- 
function PickVPlayer() 
local chat = outputChatBox 
local virusPlayer = getRandomPlayer ( ) 
outputServerLog ("Virus: " ..getPlayerName ( virusPlayer ).." has been choosen for virus." ) 
end 
addCommandHandler("viruspick",PickVPlayer) 
addEvent("vplayer", true) 
addEventHandler("vplayer", root, PickVPlayer) 
  

Client sided script:

  
-- 
-- Virus Script -Client Sided 
-- 
function virus (virusPlayer,vplayer) 
triggerServerEvent(virusPlayer, "vplayer", virusPlayer) 
local chat = outputChatBox 
local timervalue = 10000 
local slapvalue = 5 
if (virusPlayer == localPlayer) then 
setTimer( setElementHealth, timervalue, 1, localPlayer, getElementHealth(localPlayer) - slapvalue ) 
chat("Error: You are supposed to define a vehicle id! /vehicle id",player,255, 0, 0) 
end 
end 
addCommandHandler("virus",virus) 
  

Posted

What this has to do with exports? :o

If I understood this right, you want to trigger a server/client event.

But still, it looks kinda wierd,

First of all you used triggerServerEvent wrong. There is no "sendTo" argument, since its send to the server.

Actually this should output an error so you should have seen this on yourself.

But I guess you want to trigger a client event anyway since your virus player is chosen on server.

At client you don't need to check if its the localPlayer, at least if you use sendTo argument correctly.

Posted

I am picking a random guy at my server side script. I need to reach that player from my client sided script. This is all I am trying to do. After than player is going to get slapped bla bla bla...

So what can i do for reaching that randomly picked player from my client sided script?

Posted
local gPlayers = getElementsByType("player") 
local gRandomPlayer = math.random(1, #gPlayers) 
local gRandomPlayer = gPlayers[gRandomPlayer] 

Posted

Thank you for helping me but I am not just trying to script a virus scrip. I am trying to learn lua so if you explain me the script that you wrote here I will really appreciate it.

Posted

Well sorry, I don't understand this. :(

Server picks a player, and then this player gets slapped "by server"?

Or do you want all players do be able to slap the chosen player?

local gPlayers = getElementsByType("player") 
local gRandomPlayer = math.random(1, #gPlayers) 
local gRandomPlayer = gPlayers[gRandomPlayer] 

How is this helpful? :o

Posted

Okay here is the thing, I tried to make a virus script. Servers picks a random guy and slaps him every 10 seconds because he has got virus(randomly choosen).

Posted

Alright, now I get it.

So you need to use triggerClientEvent on the chosen player in that server function, since you want this to happen to a certain player.

Clientside just needs a function called by an event that is triggered by your server function.

function PickVPlayer() 
setTimer(setElementHealth, 10000, 0, localPlayer, getElementHealth(localPlayer)-10) 
end 
addEvent("vplayer", true) 
addEventHandler("vplayer", root, PickVPlayer) 

This would only happen for the chosen player.

EDIT:

Actually you don't even need a clientside I guess. :o

Posted

Wow I see that setelemnthealth is both client and server sided when I check the wiki. You are right i dont need a client side :D

You are a good person bonsai :D

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...