Questions & Scripts! [OSP Thread]

Users who are viewing this thread

Use this Thread to ask questions and share code!
Any Code Posted on this Thread could be used if the Creator is given Credit!
Thank you!
Rules:
Stick to The thread topic.
Be helpful or be gone.


Working code for anyone interested!
You could optimize this I'm sure, and fix it up to work to your liking!
If you find anything wrong with this script, which I'm sure you will. Help and point it out!
thats what the thread is for!
Code:
  ("medieval_life_starvation", # Medieval Life
   [
    (try_begin),
     (get_max_players, ":numb_players"),
     (try_for_range, ":player_id", 1, ":numb_players"),
       (player_is_active, ":player_id"),
       (player_get_agent_id, ":agent_id", ":player_id"),
       (agent_get_slot, ":food_amount", ":agent_id", slot_agent_food_amount),
       (lt, ":food_amount", 2), #":food_amount" < 2
       (assign, ":starve_dmg", 15),
       (store_agent_hit_points, ":hp", ":agent_id", 1),
       (val_sub, ":hp", ":starve_dmg"),
       (agent_set_hit_points, ":agent_id", ":hp",1),
       (str_store_string, s1, "@You are Starving Eat Something!"),
       (multiplayer_send_string_to_player, ":player_id", server_event_local_chat, s1),
       (le, ":hp", 0),
       (str_store_string, s2, "@You Hear Your stomach growl one last time!"),
       (multiplayer_send_string_to_player, ":player_id", server_event_local_chat, s2),
       (agent_deliver_damage_to_agent, ":agent_id", ":agent_id", 100),
     (try_end),
    (try_end),
    ]),



Edit You might wanna check that the agent is human and not a horse.
Code:
(agent_is_human, ":agent_id"),
 
Ahh i remember when i was in your shoes, i made the exact same post.  I learned how to mod from vornne's module system.  I would look at his code until it made sense.  Why he was doing what for what, and eventually i was able to write code fluently, did not take long.

Keep at it young grasshopper. 

The way to learn sometimes, is for people to hand you code, so you can learn from it.  I will try to assist. 

I learned how to make my invasion mod by people pretty much making me a broken mission template to fix.  It taught me a lot about timers, and how useful they are. 

1) in vornns' module system, to make a timer, you will need to make a prefix of sorts for the timer, than put the timer prefix name in order around the bottom of mission templates.  so for example look for agent_check_loop, which is a timer name, and search for it again, you will see at the bottom it is triggered on at the end, it is different than dealing with a mission in native. 
 
Xaphan said:
Ahh i remember when i was in your shoes, i made the exact same post.  I learned how to mod from vornne's module system.  I would look at his code until it made sense.  Why he was doing what for what, and eventually i was able to write code fluently, did not take long.

Keep at it young grasshopper. 

The way to learn sometimes, is for people to hand you code, so you can learn from it.  I will try to assist. 

I learned how to make my invasion mod by people pretty much making me a broken mission template to fix.  It taught me a lot about timers, and how useful they are. 

1) in vornns' module system, to make a timer, you will need to make a prefix of sorts for the timer, than put the timer prefix name in order around the bottom of mission templates.  so for example look for agent_check_loop, which is a timer name, and search for it again, you will see at the bottom it is triggered on at the end, it is different than dealing with a mission in native.


So basically ?
Code:
    welcome_message,
    turn_windmill_fans,
    ambient_sounds_check,
    music_situation_check,
    shadow_recalculation,
    my_trigger,
 
Place the trigger at the correct position in the trigger list.
If you for example would add your trigger below the agent_hit then your trigger should also be below agent_hit in the trigger list.
 
decapitation script not working
its being called on agent_hit in mission templates
can anyone shed some light? maybe I'm not seeing something

Code:
  ("medieval_life_decap", # server: check for scripted effects when the agent is hit by a special item; sets damage dealt when be called from ti_on_agent_hit
   [(store_script_param, ":attacked_agent_id", 1), # must be valid
    (store_script_param, ":attacker_agent_id", 2), # must be valid
    (store_trigger_param_3, ":damage_dealt"),

    (try_begin),
      (agent_is_human, ":attacked_agent_id"),
      (ge, ":damage_dealt", 1), # 1 for testing!
      (agent_get_position, pos1, ":attacked_agent_id"),
      (get_distance_between_positions, ":distance", pos1, pos0), 
      (is_between, ":distance", 160, 176), # If neck hit
      (agent_get_item_slot, ":item", ":attacked_agent_id", 4),
      (agent_unequip_item, ":attacked_agent_id", ":item"),
      (agent_equip_item, ":attacked_agent_id", "itm_invisible_head"), # Replace with invisible head
      (particle_system_burst, "psys_game_blood_2", pos1, 125), # Blood
      (agent_deliver_damage_to_agent, ":attacker_agent_id", ":attacked_agent_id", 100),
      (str_store_string, s3, "@You Decapitated your foe!"),
      (multiplayer_send_string_to_player, ":attacker_agent_id", server_event_local_chat, s2),
      (set_spawn_position, pos1)
    (try_end), 

    ]),
 
You should put more effort in understanding than asking. Understand the code cause we can't just code everything working for you.
Debug or display messages can help in finding errors
 
domipoppe said:
You should put more effort in understanding than asking. Understand the code cause we can't just code everything working for you.
Debug or display messages can help in finding errors
The code should work


its just missing a (try_begin), so that it doesn't throw an error if the agent doesn't have a head item equipped.
every operation i used i understand what it does. so to me the code should work but it doesn't.
Thats why i came here. not so you can give me working code but for someone to point me in the right direction


I have an idea i think i have to sync client and server but i don't know how to achieve this. anyone know?


Code:
  ("medieval_life_decap",
   [(store_script_param, ":attacked_agent_id", 1), # must be valid
    (store_script_param, ":attacker_agent_id", 2), # must be valid
    (store_trigger_param_3, ":damage_dealt"),


    (try_begin),
      (agent_is_human, ":attacked_agent_id"),
      (ge, ":damage_dealt", 1), # 1 for testing!
      (agent_get_position, pos1, ":attacked_agent_id"),
      (get_distance_between_positions, ":distance", pos1, pos0), 
      (is_between, ":distance", 160, 176), # If neck hit
      (agent_get_item_slot, ":item", ":attacked_agent_id", 4),
      (agent_unequip_item, ":attacked_agent_id", ":item"),
      (try_begin),
        (eq, ":item", 1),
        (agent_unequip_item, ":attacked_agent_id", ":item"),
      (try_end),
      (agent_equip_item, ":attacked_agent_id", "itm_invisible_head"), # Replace with invisible head
      (particle_system_burst, "psys_game_blood_2", pos1, 125), # Blood
      (agent_deliver_damage_to_agent, ":attacker_agent_id", ":attacked_agent_id", 100),
      (str_store_string, s3, "@You Decapitated your foe!"),
      (multiplayer_send_string_to_player, ":attacker_agent_id", server_event_local_chat, s2),
      (set_spawn_position, pos1)
    (try_end), 


    ]),
 
You unequip the agents item slot "4" which doesn`t exist I think, check if its weapon id 1 and then unequip it again. Wheres the sense?
Get the head slot and check if its gt than 0 - this will go valid if the agent has a head armor.

You are not displaying/logging the execution of the scripts so from where you can be sure that it is valid and correct?
Still unequip should still automatically sync.
 
domipoppe said:
You unequip the agents item slot "4" which doesn`t exist I think, check if its weapon id 1 and then unequip it again. Wheres the sense?
Get the head slot and check if its gt than 0 - this will go valid if the agent has a head armor.

You are not displaying/logging the execution of the scripts so from where you can be sure that it is valid and correct?
Still unequip should still automatically sync.
Sorry i made some changes to it and was tired didn't realize that
Code:
  ("medieval_life_decap", # server: check for scripted effects when the agent is hit by a special item; sets damage dealt when be called from ti_on_agent_hit
   [(store_script_param, ":attacked_agent_id", 1), # must be valid
    (store_script_param, ":attacker_agent_id", 2), # must be valid
    (store_trigger_param_3, ":damage_dealt"),


    (try_begin),
      (agent_is_human, ":attacked_agent_id"),
      (is_between, ":damage_dealt", 1, 99),
      (agent_get_position, pos1, ":attacked_agent_id"),
      (get_distance_between_positions, ":distance", pos1, pos0), 
      (is_between, ":distance", 160, 176), # If neck hit
      (agent_get_item_slot, ":item", ":attacked_agent_id", ek_head),
      (try_begin),
        (eq, ":item", 1),
        (agent_unequip_item, ":attacked_agent_id", ":item"),
      (try_end),
      (agent_equip_item, ":attacked_agent_id", ":itm_invisible_head"), # for the server combat calculations
      (particle_system_burst, "psys_game_blood_2", pos1, 125), # Blood
      (str_store_string, s3, "@You Decapitated your foe!"),
      (multiplayer_send_string_to_player, ":attacker_agent_id", server_event_local_chat, s2),
      (set_spawn_position, pos1),
    (try_end), 


    ]),
 
      (str_store_string, s3, "@You Decapitated your foe!"),
      (multiplayer_send_string_to_player, ":attacker_agent_id", server_event_local_chat, s2),
 
Arthur_Pendragon said:
Code:
       (player_get_agent_id, ":agent_id", ":player_id"),
       (agent_get_slot, ":food_amount", ":agent_id", slot_agent_food_amount),
Always check that the agent id returned by player_get_agent_id is valid, using agent_is_active and agent_is_alive if needed: players can exist but have no associated valid agent (they have just joined, or have been spectating for more than 30 seconds).
Arthur_Pendragon said:
Code:
      (agent_get_item_slot, ":item", ":attacked_agent_id", ek_head),
      (try_begin),
        (eq, ":item", 1),
        (agent_unequip_item, ":attacked_agent_id", ":item"),
      (try_end),
Checking that the item id in the head equip slot is 1 (itm_no_head) is not likely to ever be true: that item is only used as a placeholder for the network message to clients, to remove the current head armor. In any case, you should never compare a variable containing an item id to any number greater than -1, but use the specific item identifier you want instead (such as "itm_no_head"); otherwise your code will break unexpectedly if any items are added before it in the list, besides the issue of the code being much harder to understand.
Arthur_Pendragon said:
Code:
      (agent_equip_item, ":attacked_agent_id", ":itm_invisible_head"), # for the server combat calculations
Body armor is not synchronized visibly to clients in the Warband engine: you should call the "change_armor" PW script which is designed for this purpose (server side only).
 
Achilles MçDonald™ said:
      (str_store_string, s3, "@You Decapitated your foe!"),
      (multiplayer_send_string_to_player, ":attacker_agent_id", server_event_local_chat, s2),
Yes thank you that was a silly mistake still the code was broken for other reasons.


Vornne said:
Arthur_Pendragon said:
Code:
       (player_get_agent_id, ":agent_id", ":player_id"),
       (agent_get_slot, ":food_amount", ":agent_id", slot_agent_food_amount),
Always check that the agent id returned by player_get_agent_id is valid, using agent_is_active and agent_is_alive if needed: players can exist but have no associated valid agent (they have just joined, or have been spectating for more than 30 seconds).
Arthur_Pendragon said:
Code:
      (agent_get_item_slot, ":item", ":attacked_agent_id", ek_head),
      (try_begin),
        (eq, ":item", 1),
        (agent_unequip_item, ":attacked_agent_id", ":item"),
      (try_end),
Checking that the item id in the head equip slot is 1 (itm_no_head) is not likely to ever be true: that item is only used as a placeholder for the network message to clients, to remove the current head armor. In any case, you should never compare a variable containing an item id to any number greater than -1, but use the specific item identifier you want instead (such as "itm_no_head"); otherwise your code will break unexpectedly if any items are added before it in the list, besides the issue of the code being much harder to understand.
Arthur_Pendragon said:
Code:
      (agent_equip_item, ":attacked_agent_id", ":itm_invisible_head"), # for the server combat calculations
Body armor is not synchronized visibly to clients in the Warband engine: you should call the "change_armor" PW script which is designed for this purpose (server side only).
Thank you vornne i got it working!
 
Back
Top Bottom