Jump to content

Functions.


Sparrow

Recommended Posts

Hello there, new scripter!

As you're a new scripter, I'd suggest to start from the scripting manual. I started my scripting from there aswell, now I am an advanced scripter (I think, heh').

'Creating a server' manual: https://wiki.multitheftauto.com/wiki/Server_Manual

Scripting introduction: https://wiki.multitheftauto.com/wiki/Scr ... troduction

Server-Side

Functions: https://wiki.multitheftauto.com/wiki/Ser ... _Functions

Events: https://wiki.multitheftauto.com/wiki/Ser ... ing_Events

Client-Side

Functions: https://wiki.multitheftauto.com/wiki/Cli ... _Functions

Events: https://wiki.multitheftauto.com/wiki/Cli ... ing_Events

Link to comment

Is it as that?

Client:

local maxPing = 350 
  
function checkPing() 
    local ping = getPlayerPing(source) 
    if (ping > 350) then 
        outputChatBox("#FF0000Your ping is high, lower it please.", source) 
    end 
end 
addEventHandler("onPlayerJoin", getRootElement(), checkPing) 
  
function getPings()  
    if getPlayerPing(getLocalPlayer()) >= maxPing then  
        triggerServerEvent("ping.onKickHighPing",getLocalPlayer(),getPlayerPing(getLocalPlayer())) 
    end 
end 
setTimer (5000,0) 

Server:

local maxPing = 350 
  
function onHighPing() 
    kickPlayer(source,source,"Your ping is over the limit. (over "..maxPing..")")  
    outputChatBox("#FF0000"..getPlayerName(source).."#FF0000 has been kicked for high ping.",root,255,0,0,true) 
end 
  
addEvent( "ping.onKickHighPing", true ) 
addEventHandler( "ping.onKickHighPing", getRootElement(), onHighPing ) 

Link to comment

Hey, your settimer is incorrect. Events are wrong :|

UNTESTED:

Client:

function checkPing() 
    local ping = getPlayerPing(source) 
    if (ping > 350) then 
        outputChatBox("#FF0000Your ping is high, lower it please.", source,255,255,255,true) 
    end 
end 
addEventHandler("onClientPlayerJoin", getRootElement(), checkPing) 
  
function triggerPingKicker() 
    if getPlayerPing(getLocalPlayer()) >= maxPing then 
        triggerServerEvent("ping.onKickHighPing",getLocalPlayer(),getPlayerPing(getLocalPlayer())) 
    end 
end 
setTimer(triggerPingKicker,5000,0) 

Server:

local maxPing = 350 
  
function onHighPing() 
    kickPlayer ( thePlayer, "Your ping is over the limit. (over "..maxPing..")" ) 
    outputChatBox("#FF0000"..getPlayerName(source).."#FF0000 has been kicked for high ping.",root,255,0,0,true) 
end 
  
addEvent( "ping.onKickHighPing", true ) 
addEventHandler( "ping.onKickHighPing", getRootElement(), onHighPing ) 

Link to comment

Lol i changed many things. In your client you used onPlayerJoin as the event handler?!?!?!!? UM ?!?!? Its onClientPlayerJoin...

and

outputChatBox("#FF0000Your ping is high, lower it please.", source) didnt support colors, now it does....

and

ofc your settimer was WRONG!

and

kickPlayer in the server was used incorrectly?!?!?!?!?! I basically simplified it!

Could you please read my code carefully next time! I really hate justifying myself.

Link to comment

Client:

function checkPing() 
    local ping = getPlayerPing(source) 
    if (ping > 350) then 
        outputChatBox("#FF0000Your ping is high, lower it please.", source,255,255,255,true) 
    end 
end 
addEventHandler("onClientPlayerJoin", getRootElement(), checkPing) 
  
function triggerPingKicker() 
    if getPlayerPing(getPlayerName(getLocalPlayer())) >= maxPing then 
        triggerServerEvent("ping.onKickHighPing",getLocalPlayer(),getPlayerPing(getLocalPlayer())) 
    end 
end 
setTimer(triggerPingKicker,5000,0) 

Server:

local maxPing = 350 
  
function onHighPing() 
    kickPlayer ( thePlayer, "Your ping is over the limit. (over "..maxPing..")" ) 
    outputChatBox("#FF0000"..getPlayerName(source).."#FF0000 has been kicked for high ping.",root,255,0,0,true) 
end 
  
addEvent( "ping.onKickHighPing", true ) 
addEventHandler( "ping.onKickHighPing", getRootElement(), onHighPing ) 

Try this one. i attempted to use getPlayerName(getLocalPlayer()). Let me know of more errors if any persist.

Link to comment

-- client side:

local maxPing = 350 
  
function checkPing() 
    local ping = getPlayerPing(source) 
    if (ping > tonumber(maxPing)) then 
        outputChatBox("#FF0000Your ping is high, lower it please.", source,255,255,255,true) 
    end 
end 
addEventHandler("onClientPlayerJoin", getRootElement(), checkPing) 
  
function triggerPingKicker() 
    if (getPlayerPing(localPlayer) >= tonumber(maxPing)) then 
        triggerServerEvent("ping.onKickHighPing",localPlayer,maxPing) 
    end 
end 
setTimer(triggerPingKicker,5000,0) 

-- server side:

function onHighPing(maxPing) 
    kickPlayer ( thePlayer, "Your ping is over the limit. (over "..maxPing..")" ) 
    outputChatBox("#FF0000"..getPlayerName(source).."#FF0000 has been kicked for high ping.",root,255,0,0,true) 
end 
addEvent( "ping.onKickHighPing", true ) 
addEventHandler( "ping.onKickHighPing", getRootElement(), onHighPing ) 

Link to comment
  • 2 weeks later...
you can remove all these resources and add

  
<object name="resource.*"></object> 
  

But that defeats the purpose of ACL..

You might as well do user.* and it's as good as deleted :|

giving all resources admin rights wont make a problem , because you are the one who installing the resources so you must be sure about what you are installing =D

Link to comment

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...