Scripts / Switch problems with counter

Author
Message
vrg
9
Years of Service
User Offline
Joined: 27th Aug 2014
Location: Netherlands
Posted: 8th Dec 2023 23:17
What is wrong , it is not working, thanks

-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Switch with counter

local combiswitch = {}
function combiswitch_init(e)
CombiSwitch = 0
end

function combiswitch_main(e)
PlayerDist = GetPlayerDistance(e)
if CombiSwitch == 0 then
if PlayerDist < 200 and g_PlayerHealth > 0 then
Prompt("Press E key to activate combiswitch")
if g_KeyPressE == 1 then
CombiSwitch = 1
PromptDuration("CombiSwitch activated" ,3000)
CS=CS+1
if CS == 6 then Prompt("Game finished")
end
end
end
end
end

Laptop MSI Vector GP66 , I7 processor 12th Gen Intel(R) Core(TM) i7-12700H 2.70 GHz, Nvidia graphics RTX 3060, 16 Gb memory
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 9th Dec 2023 09:41
Well apart from the fact that CS will never get beyond 1 because as soon as you activate the first time that code is no longer reachable I can't see much wrong with it.

Of course it would help if you describe what you expect it to do and define what you mean by 'it is not working'.
Been there, done that, got all the T-Shirts!
PM
vrg
9
Years of Service
User Offline
Joined: 27th Aug 2014
Location: Netherlands
Posted: 9th Dec 2023 12:17
AmenMose . Thanks. When I approach the switch in the game it is not reacting I don't see "E"to activate. I think I need a global counter to count the switches I activate
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 9th Dec 2023 13:51
Well the first thing you should always do when trying out a script for the first time is add a PromptLocal( e, "here") at the start of the _main function, that will then show up in test as a prompt where the entity is on the map if the script is actually being executed.

Usual reasons a script will not execute (in no particular order of likelihood):

1) Entity is static. Must be dynamic to allow a script to run.
2) Script name does not match functions. So for example your functions are combiswitch_init & combiswitch_main so the script *must* be called combiswitch.lua. (Lua is case sensitive btw).
3) Entity may be too far from player. Set the always active to yes if you want scripts to work that are attached to entities more than 3000 units (IIRC) away from the player.

Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 9th Dec 2023 13:53
btw, can you delete the other two threads please, one is enough.
Been there, done that, got all the T-Shirts!
PM
vrg
9
Years of Service
User Offline
Joined: 27th Aug 2014
Location: Netherlands
Posted: 13th Dec 2023 19:04
AmenMoses thanks for the reaction

Login to post a reply

Server time is: 2024-05-05 12:49:05
Your offset time is: 2024-05-05 12:49:05