Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google Log In with Steam Sign In
  • Create Account
Photo

Need help with a lua script.

- - - - -

  • Please log in to reply
15 replies to this topic

#1
OFFLINE   Nachz

Nachz

    Newbie

  • Members
  • Pip
  • 7 posts
4
A step in the right direction

Hi all, I'm working on a lua script that would give xp to new player under 1000xp. So they would have all skills. But I can't make it done... I tried 2 ways and both didn't worked well.

 

My lua is based on a other script between.

 

So I have been using this code for when the player spawn:

function et_ClientSpawn(clientNum, revived, teamChange, restoreHealth)
   local valXP = getXP(clientNum)
   if valXP < noexp then    
      setexp(clientNum)
   end
end

The value of noexp is 1000.

 

This is the first thing I tried (fonction setexp):

function setexp(playerID)
   local name = et.gentity_get(playerID,"pers.netname")
   local silentguid = et.gentity_get(playerID,"sess.guid")
   if isBot(playerID) or noGuid(playerID) then return end
      et.trap_SendServerCommand(-1,"chat \"^nCongratulations ^7"..name.."^n, ^nyou have ^nbeen ^nEXP! \"")
      et.trap_SendConsoleCommand( et.EXEC_APPEND, "givexp "..silentguid.." SOLD 500 \n" )
      et.trap_SendConsoleCommand( et.EXEC_APPEND, "givexp "..silentguid.." MED 500 \n" )
      et.trap_SendConsoleCommand( et.EXEC_APPEND, "givexp "..silentguid.." ENG 500 \n" )
      et.trap_SendConsoleCommand( et.EXEC_APPEND, "givexp "..silentguid.." FOPS 500 \n" )
      et.trap_SendConsoleCommand( et.EXEC_APPEND, "givexp "..silentguid.." COV 500 \n" )
      et.trap_SendConsoleCommand( et.EXEC_APPEND, "givexp "..silentguid.." LIGHT 500 \n" )
      et.trap_SendConsoleCommand( et.EXEC_APPEND, "givexp "..silentguid.." BATTLE 500 \n" )
      et.trap_SendConsoleCommand( et.EXEC_APPEND, "readconfig\n" )
end

But I realized that the command givexp use the silent ID when I'm using the Silent GUID because I didn't find any function that allow to get the silent ID. Maybe something that would only take the 8 last characters of the silent GUID could give the Silent ID, but I don't know how. (So I didn't got xp, I only seen the message)

 

so then I tried this using the G_AddSkillPoints...

function setskill(playerID)
   local name = et.gentity_get(playerID,"pers.netname")
   if isBot(playerID) or noGuid(playerID) then return end
      et.G_AddSkillPoints("..playerID..", 0, 500)
      et.G_AddSkillPoints("..playerID..", 1, 500)
      et.G_AddSkillPoints("..playerID..", 2, 500)	
      et.G_AddSkillPoints("..playerID..", 3, 500)	
      et.G_AddSkillPoints("..playerID..", 4, 500)	
      et.G_AddSkillPoints("..playerID..", 5, 500)	
      et.G_AddSkillPoints("..playerID..", 6, 500)
      et.G_AddSkillPoints("..playerID..", 1, 500)		  
      et.trap_SendServerCommand(-1,"chat \"^nCongratulations ^7"..name.."^n, ^nyou have ^nbeen ^nEXP! Welcome to MC ! \"")
	  et.trap_SendConsoleCommand( et.EXEC_APPEND, "readconfig\n" )
      
end

I think there are something missing, because the lua can get load when I type "/lua_status" I can see it.

 

Thanks for you help

 

Nachz



#2
OFFLINE   Zelly

Zelly

    Regular Member

  • Coders
  • PipPipPip
  • 141 posts
73
Getting Better
I am curious if all your trying to accomplish is to have players start with all skills then I think it would be easier to just set the skill levels to 0.
 
http://mygamingtalk....r#skill_soldier

You then wouldn't need to bother with lua, everyone that joined would automatically have the skill levels.
In your server config:
set skill_soldier      "0 0 0 0"
set skill_medic        "0 0 0 0"
set skill_engineer     "0 0 0 0"
set skill_fieldops     "0 0 0 0"
set skill_covertops    "0 0 0 0"
set skill_battlesense  "0 0 0 0"
set skill_lightweapons "0 0 0 0"
However if you wanted to do this for some newer players that like receiving xp.
You are trying to concatenate a string into where you are supposed to be supplying an integer(the client number)
Try this:
function setskill(playerID)
   local name = et.gentity_get(playerID,"pers.netname")
   if isBot(playerID) or noGuid(playerID) then return end
   et.G_AddSkillPoints(playerID, 0, 500)
   et.G_AddSkillPoints(playerID, 1, 500)
   et.G_AddSkillPoints(playerID, 2, 500)	
   et.G_AddSkillPoints(playerID, 3, 500)	
   et.G_AddSkillPoints(playerID, 4, 500)	
   et.G_AddSkillPoints(playerID, 5, 500)	
   et.G_AddSkillPoints(playerID, 6, 500)
   et.G_AddSkillPoints(playerID, 1, 500)		  
   et.trap_SendServerCommand(-1,"chat \"^nCongratulations ^7"..name.."^n, ^nyou have ^nbeen ^nEXP! Welcome to MC ! \"")
   -- et.trap_SendConsoleCommand( et.EXEC_APPEND, "readconfig\n" )
   -- Pretty sure you don't need readconfig in this situation
end
Also you are sending your congratulations message to everyone that is connected. Not sure if this is intended or not, if not replace -1 with playerID

Hope that helps, btw if you can check your console log around the time the map is getting loaded it will show if there are any errors when loading your lua. They are usually pretty useful when trying to pinpoint what is wrong.

#3
OFFLINE   gaoesa

gaoesa

    Advanced Member

  • Management
  • PipPipPipPip
  • 4391 posts
341
Will become famous
  • LocationFinland

Also, you can get the 8 character id from the sess.guid with substring 

string.sub(s, i [, j])

http://lua-users.org...LibraryTutorial. The last 8 characters of the sess.guid is the silent id for the command.



#4
OFFLINE   Nachz

Nachz

    Newbie

  • Members
  • Pip
  • 7 posts
4
A step in the right direction

Thanks for the fast answer, I will try it ;)

 

Edit: It worked, thanks you :D

 

Also to you know how to force the client to downlaod a .pk3 files in the etmain folder. The sv_pure only force the client to download pk3 files in the silent folder.

 

Thanks you again


Edited by Nachz, 09 March 2015 - 05:57 PM.


#5
OFFLINE   Zelly

Zelly

    Regular Member

  • Coders
  • PipPipPip
  • 141 posts
73
Getting Better
Not 100% sure.
Related topic? http://mygamingtalk....2-in-game-menu/

#6
OFFLINE   twt_thunder

twt_thunder

    Regular Member

  • Members
  • PipPipPip
  • 68 posts
13
A step in the right direction
  • LocationNorway

 

Also to you know how to force the client to downlaod a .pk3 files in the etmain folder. The sv_pure only force the client to download pk3 files in the silent folder.

 

 

you need an .ARENA file inside if ET should find a file in ETmain.

Now, I would say dont do it, putting things in etmain screws up peoples ET.....



#7
OFFLINE   Nachz

Nachz

    Newbie

  • Members
  • Pip
  • 7 posts
4
A step in the right direction

you need an .ARENA file inside if ET should find a file in ETmain.
Now, I would say dont do it, putting things in etmain screws up peoples ET.....


Well I only want player to download a pk3 file that contains a modified main.menu.

So I take notepad+ and I save an empty file with a .ARENA extension and I add it to my .pk3 ?

#8
OFFLINE   twt_thunder

twt_thunder

    Regular Member

  • Members
  • PipPipPip
  • 68 posts
13
A step in the right direction
  • LocationNorway

not sure if it can be empty, try it.. but again, I would keep it in modfolder....



#9
OFFLINE   Nachz

Nachz

    Newbie

  • Members
  • Pip
  • 7 posts
4
A step in the right direction
Well the lua script can be exploited. I don't know why but during warmup the xp of all player are all under 1000xp so the script still give skill points, but it wont work so it's fine. But after the warmup, when a player die, he respawn and get again skill points plus the XP.

Anybody knows how to fix that ? And why the current xp of the player isn't loaded well while warmup...

Here is the getXP fonction:
function getXP(playerID)
   return  et.gentity_get(playerID, "ps.persistant", 0)   
end
And I don't know if there is a function that only get execute after the warmup and that would do something like this one:

function et_ClientSpawn(clientNum, revived, teamChange, restoreHealth)
   local valXP = getXP(clientNum)
   if valXP < noexp then    
      setexp(clientNum)
   end
end
Thanks in advance

Edited by Nachz, 14 March 2015 - 04:04 AM.


#10
OFFLINE   Zelly

Zelly

    Regular Member

  • Coders
  • PipPipPip
  • 141 posts
73
Getting Better
Hmm... to fix warmup xp gain is pretty simple just check gamestate I always forget the correct number though.
I think it is this:
local gamestate = tonumber( et.trap_Cvar_Get('gamestate') )
if gamestate == 1 then
 -- do xp stuff here.
end
So are you saying it gives xp to players that have more than 1000 xp every spawn? or Just once.
If it is just once then I assume it is related to a small bug, where xp from lua is 0 until at least one xp is gained: http://mygamingtalk....a-get-xp-value/
I would have to do some more testing my self again to verify a good method to get xp in lua, I forget which method I normally use.
Try this:
(Disclaimer this is off the top of my head not sure if this is right)
function getXP(clientNum)
   local xp = 0
   for k=0, 6 do
      xp = xp + tonumber(et.gentity_get(clientNum,"sess.skillpoints",k))
   end
   return xp
end
Hope that helps, I didn't do any fact checking.

#11
OFFLINE   Nachz

Nachz

    Newbie

  • Members
  • Pip
  • 7 posts
4
A step in the right direction

The new getXP fonction you gave me, works pretty well.

 

And I added this to my setskills function:

local gamestate = tonumber( et.trap_Cvar_Get('gamestate') )
   if gamestate == 0 then
   et.G_AddSkillPoints(playerID, 0, 500)
   et.G_AddSkillPoints(playerID, 1, 500)
   et.G_AddSkillPoints(playerID, 2, 500)	
   et.G_AddSkillPoints(playerID, 3, 500)	
   et.G_AddSkillPoints(playerID, 4, 500)	
   et.G_AddSkillPoints(playerID, 5, 500)	
   et.G_AddSkillPoints(playerID, 6, 500)
   et.G_AddSkillPoints(playerID, 1, 500)

And the good gamestate number was 0, because 1 is for warmup and 0 is for when the game is started.

 

Thanks a lot, my problem is fixed ! :D



#12
OFFLINE   Zelly

Zelly

    Regular Member

  • Coders
  • PipPipPip
  • 141 posts
73
Getting Better
Aha no matter how many times I do that I always get it wrong :D

#13
OFFLINE   Nachz

Nachz

    Newbie

  • Members
  • Pip
  • 7 posts
4
A step in the right direction

Also I still have few questions but it's not related with lua but with cvars. Like I would like to know why each time people who download the next map will be spectator on the nextmap so they need to choose a new team again only because they downloaded the new map...

 

And is there a way to solve the ui_x86_mp.dll server pure failed error for the player, because few players probably don't know that they need to start the game as administrator to solve this problem. So I don't know if there's a way to solve this problem throught the server.

 

Thanks again for the help



#14
OFFLINE   Zelly

Zelly

    Regular Member

  • Coders
  • PipPipPip
  • 141 posts
73
Getting Better
set sv_wwwDlDisconnected 0
I think.

As for the second problem I don't think so.
I recommend installing ET Outside program files then you don't have that problem. But again somehow you need to get that to your players.

This problem comes up so often usually most players can figure it out with google. It is still best if you have a clan website to make it easy for people to find the solution.

#15
OFFLINE   Nachz

Nachz

    Newbie

  • Members
  • Pip
  • 7 posts
4
A step in the right direction

Thanks for the cvar, I really forgot this one.

 

Also I'm working on something else and the lua module don't want to load so I guess there is a problem with one of these function:

function et_Obituary(victim,killer,meansOfDeath)
      getkiller(victim,killer)
     	 
end

function getkiller(victimID,killerID)
   local hpkiller = et.gentity_get(killerID,"ps.stats",0)
   local name = et.gentity_get(killerID,"pers.netname")
   et.trap_SendServerCommand(victimID,"chat \"^7 "..name.." was at ^1"..hpkiller.." ^7HP when he killed you !\"")
   -- et.trap_SendConsoleCommand( et.EXEC_APPEND, "readconfig\n" )
   -- Pretty sure you don't need readconfig in this situation
   end
end

Thanks ! :D

 

Edit: Right after I posted the code I saw my error ^^ Fixed.


Edited by Nachz, 15 March 2015 - 06:47 PM.


#16
OFFLINE   Oxyzium

Oxyzium

    Regular Member

  • Banned
  • PipPipPip
  • 66 posts
5
A step in the right direction
function et_Obituary(victimnum, killernum, meansofdeath)
    local victimteam = tonumber(et.gentity_get(victimnum, "sess.sessionTeam"))
    local killerteam = tonumber(et.gentity_get(killernum, "sess.sessionTeam"))
    
    if victimteam ~= killerteam and killernum ~= 1022 then
        local killername = string.gsub(et.gentity_get(killernum, "pers.netname"), "%^$", "^^ ")
        local killerhp = et.gentity_get(killernum, "health")
       
        --et.trap_SendServerCommand(victimnum, string.format("cpm \"^7Your ^1killer ^7%s has %d HP remaining\n\"", killername, killerhp))

        --this sends a message to the client only
        msg = string.format("cpm  \"" .. killername ..  "^7 had^o " .. killerhp .. " ^7HP left\n")
        et.trap_SendServerCommand(victimnum, msg)
    end
end

Edited by Oxyzium, 05 April 2015 - 03:12 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users