Jump to content

Problems with calling the function


Recommended Posts

I export a function, I call the function.

This is ok, for the now.

The function is called, the parameters are correct, I made the function output everything.

But somehow, the variables are not saved in the array I made.

function givePlayerWeapon(source,type,ammount) 
 giveWeapon(source,type,ammount) 
 setWeaponAmmo(source,type,ammount) 
 gtat_rba_player[source]["weapons"][type]=ammount 
end 
addEvent("gtat_rba_giveWeapon",true) 
addEventHandler("gtat_rba_giveWeapon", getRootElement(), givePlayerWeapon) 
  

(I tested it with both, export and EventHandler, so don't ask me why there is any "addEventHandler" in there.)

Notes: getClientName(source) returns the correct player.

outputChatBox(type .. ammount) returns the correct values.

Now, I ask for the value of gtat_rba_giveWeapon[player]["weapons"][weapontype] for the lulz.

  
function gunfire( hitElement, weapon, ammo)  
  if (gtat_rba_player[source]["weapons"][weapon]) then  
   gtat_rba_player[source]["weapons"][weapon]=gtat_rba_player[source]["weapons"][weapon]-1 
   if (gtat_rba_player[source]["weapons"][weapon]<ammo-1) then 
    setWeaponAmmo ( source, weapon, gtat_rba_player[source]["weapons"][weapon] ) 
    --outputChatBox(getClientName(source) .. "got one 'AMMO CHEAT' point") 
    setPlayerWeaponSlot(source, 0) 
    gtat_rba_player[source]["cheatcount"] = gtat_rba_player[source]["cheatcount"]+1 
    gtat_rba_player[source]["ammocheatcount"] = gtat_rba_player[source]["ammocheatcount"]+1 
    if (gtat_rba_player[source]["weapons"][weapon]<ammo-100) then 
     logEvent ( source, "Ammo cheat - unknown source" ) 
     outputConsole("Anticheat detected ammo cheat at player " .. getClientName(source) .. " This is very inconvenient. The event has been logged." .. gtat_rba_player[source]["weapons"][weapon])  
     kickPlayer ( source , nil , "Anticheat detected ammo cheat. This is very inconvenient. The event has been logged." .. gtat_rba_player[source]["weapons"][weapon]) 
    end 
   end 
  else 
   logEvent ( source, "Weapon cheat - unknown source" ) 
   outputConsole("Anticheat detected ammo cheat at player " .. getClientName(source) .. " This is very inconvenient. The event has been logged." .. weapon)  
   kickPlayer ( source , nil , "Anticheat detected ammo cheat. This is very inconvenient. The event has been logged." .. weapon) 
  end  
end 
addEvent("gtat_rba_gunfire",true) 
addEventHandler ( "gtat_rba_gunfire", getRootElement(), gunfire ) 
  

This works, when the upper call is just called by ONE script, lets call it "the first script". As soon as I ask a second script to set the value to something which is higher then the previous value, the player gets kicked.

I used this function on purpose, since it contains " setWeaponAmmo(source,type,ammount)". This way I prevent the mistake that may occur when different weapons use the same weaponslot and ammo.

At the moment I have no idea why it happens.

Using just one script to call the function/call the event works fine, using a second script results in a kick.

Link to comment

The array won't be saved... What kind of array? The one in the called function or the one like "something=call(..."? In case of the 2nd, I would not be surprised. It doesn't return anything without defining what to return with "return ".

Link to comment

Local array, which gets a new sub array as soon as a player joins the game.

Why should the second function return anything?

It just gets called every weapon fire and kicks the player, when it supposes he cheats.

Also, the array IS saved when the callbacks are used by only one script.

As soon as they are used by two scripts at the same time, it kicks when you have more then the first started script which calls the function told the anticheat you have.

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